import minist时候报错No module named mnist如何解决
生活随笔
收集整理的這篇文章主要介紹了
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 -> 10def 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 0return out, loss, accprint('MNIST CNN 初始化!') loss = 0 num_correct = 0for i, (im, label) in enumerate(zip(test_images, test_labels)):# 向前傳遞_, l, acc = forward(im, label)loss += lnum_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 = 0num_correct = 0整體代碼鏈接:
https://blog.csdn.net/zimiao552147572/article/details/92801266
初次懷疑是不是被刪了,因為都是tensorflow在使用minist。
import沒有錯,錯的是確實有這個包,需要pip導入
pip install mnist(不要打錯mnist)
希望能幫助我,謝謝!
總結
以上是生活随笔為你收集整理的import minist时候报错No module named mnist如何解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 初中女生学计算机好还是学医好,女生学医选
- 下一篇: 证件照制作v2.9.36