import minist时候报错No module named mnist如何解决

import minist的时候报错:
No module named ‘mnist’

部分代码:

import mnist
import numpy as np
from conv import Conv3x3
from maxpool import MaxPool2
from softmax import Softmax
 
# 训练集文件
#train_images_idx3_ubyte_file = '../../data/mnist/bin/train-images.idx3-ubyte'
# 训练集标签文件
#train_labels_idx1_ubyte_file = '../../data/mnist/bin/train-labels.idx1-ubyte'

# 测试集文件
test_images_idx3_ubyte_file = r't10k-images.idx3-ubyte'
# 测试集标签文件
test_labels_idx1_ubyte_file = r't10k-labels.idx1-ubyte'

#我们只使用前1K测试示例(全部是10K个)。为了时间的利益。如果你想的话,可以随意改变
test_images = mnist.test_images()[:1000]
test_labels = mnist.test_labels()[:1000]
 
conv = Conv3x3(8)                  # 28x28x1 -> 26x26x8
pool = MaxPool2()                  # 26x26x8 -> 13x13x8
softmax = Softmax(13 * 13 * 8, 10) # 13x13x8 -> 10
 
def forward(image, label):
 
	#完成CNN的前向传递并计算准确度和交叉熵损失。
	#图像是二维numpy数组。标签是数字
	#我们将图像从[0,255]转换为[-0.5,0.5]以使其更容易。一起工作。这是标准做法。
 
	out = conv.forward((image / 255) - 0.5)
	out = pool.forward(out)
	out = softmax.forward(out)
 
	# 计算交叉熵损失和精度。np.log() 是自然日志
	loss = -np.log(out[label])
	acc = 1 if np.argmax(out) == label else 0
 
	return out, loss, acc
 
print('MNIST CNN 初始化!')
loss = 0
num_correct = 0
 
for i, (im, label) in enumerate(zip(test_images, test_labels)):
	# 向前传递
	_, l, acc = forward(im, label)
	loss += l
	num_correct += acc
 
	# 每100步打印一次统计数据
	if i % 100 == 99:
		print('[Step %d] Past 100 steps: Average Loss %.3f | Accuracy: %d%%'%(i + 1, loss/100, num_correct) )
		loss = 0
		num_correct = 0

整体代码链接:
https://blog.csdn.net/zimiao552147572/article/details/92801266

初次怀疑是不是被删了,因为都是tensorflow在使用minist。
import没有错,错的是确实有这个包,需要pip导入

pip install mnist(不要打错mnist)
希望能帮助我,谢谢!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值