3.6 손글씨 숫자 인식 from dataset.mnist import load_mnist

반응형

책에서는

이라고 나와 있다 설명 데로 라면 github에서

https://github.com/WegraLee/deep-learning-from-scratch

 

WegraLee/deep-learning-from-scratch

『밑바닥부터 시작하는 딥러닝』(한빛미디어, 2017). Contribute to WegraLee/deep-learning-from-scratch development by creating an account on GitHub.

github.com

로 접속하여

ZIP압축 파일을 다운 받아 압축을 풀고(물론 맥은 다운 받으면 바로 풀리겠지만)

ch03폴더에서 mnist_show.py파일을 실행하면

# coding: utf-8
import sys, os
sys.path.append(os.pardir)  # 부모 디렉터리의 파일을 가져올 수 있도록 설정
import numpy as np
from dataset.mnist import load_mnist
from PIL import Image


def img_show(img):
    pil_img = Image.fromarray(np.uint8(img))
    pil_img.show()

(x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=False)

img = x_train[0]
label = t_train[0]
print(label)  # 5

print(img.shape)  # (784,)
img = img.reshape(28, 28)  # 형상을 원래 이미지의 크기로 변형
print(img.shape)  # (28, 28)

img_show(img)

Traceback (most recent call last):
  File "/Users/anbyeong-ug/Downloads/deep-learning-from-scratch-master/ch03/mnist_show.py", line 5, in <module>
    from dataset.mnist import load_mnist
ModuleNotFoundError: No module named 'dataset'

이 친구 말이 다르다

dataset을 못 찾아 오류가 난다

자....장난??????

sys.path,append(os.pardir)

#부모 디렉터리의 파일을 가져올 수 있도록 설정

이라는데 아무래도 여기서 문제가 생긴 듯하여

내가 직접 경로를 추가했다.

우클릭 후 Option키를 누르면 이렇게 경로 복사가 가능하다.

import sys, os
sys.path.append("/Users/anbyeong-ug/Downloads/deep-learning-from-scratch-master")  # 부모 디렉터리의 파일을 가져올 수 있도록 설정
import numpy as np
from dataset.mnist import load_mnist
from PIL import Image


def img_show(img):
    pil_img = Image.fromarray(np.uint8(img))
    pil_img.show()

(x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=False)

img = x_train[0]
label = t_train[0]
print(label)  # 5

print(img.shape)  # (784,)
img = img.reshape(28, 28)  # 형상을 원래 이미지의 크기로 변형
print(img.shape)  # (28, 28)

img_show(img)

os.pardir을 지우고

복사한 경로로 대치하면 

(""큰따움표 부쳐야함.)

앙------------ 개꿀!!!!! 성공이다.

반응형