この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 次のリビジョン | 前のリビジョン | ||
|
python:ゼロから作るdeeplearning [2021/03/03 19:32] ips 作成 |
python:ゼロから作るdeeplearning [2021/07/16 10:57] (現在) ips ↷ anaconda から python:ゼロから作るdeeplearning へページの移動と名称変更しました。 |
||
|---|---|---|---|
| ライン 45: | ライン 45: | ||
| {{:pasted:20210303-192918.png}} | {{:pasted:20210303-192918.png}} | ||
| + | |||
| + | |||
| + | ===== 3.6.1 MNISTデータセット ===== | ||
| + | |||
| + | そのままでは画像をダウンロードできない。 | ||
| + | |||
| + | <code python> | ||
| + | import numpy as np | ||
| + | import matplotlib.pylab as plt | ||
| + | import sys, os # コロンではない、カンマ | ||
| + | |||
| + | os.chdir("C:\\Users\\[user_name]\\PycharmProjects\\pythonProject\\deep-learning-from-scratch-master\\ch03") | ||
| + | sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定 | ||
| + | from dataset.mnist import load_mnist | ||
| + | from PIL import Image | ||
| + | ... | ||
| + | </code> | ||
| + | |||
| + | <code python dataset/mnist.py> | ||
| + | def _download(file_name): | ||
| + | file_path = dataset_dir + "/" + file_name | ||
| + | |||
| + | if os.path.exists(file_path): | ||
| + | return | ||
| + | |||
| + | print("Downloading " + file_name + " ... ") | ||
| + | # urllib.request.urlretrieve(url_base + file_name, file_path) #←この行をコメントアウト | ||
| + | | ||
| + | # ↓↓↓ 追加 ↓↓↓ | ||
| + | |||
| + | headers = { | ||
| + | "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0" | ||
| + | } | ||
| + | request = urllib.request.Request(url_base+file_name, headers=headers) | ||
| + | response = urllib.request.urlopen(request).read() | ||
| + | with open(file_path, mode='wb') as f: | ||
| + | f.write(response) | ||
| + | # ↑↑↑ 追加 ↑↑↑ | ||
| + | | ||
| + | print("Done") | ||
| + | |||
| + | </code> | ||
| + | |||
| + | |||
| + | ===== 3.6.2 ニューラルネットワークの推論処理 ===== | ||
| + | |||
| + | <html>NameError: name 'pickle' is not defined</html>というエラーがでる。 | ||
| + | <html>import pickle</html>を追加したらエラーが消えた。 | ||
| + | |||
| + | |||
| + | ===== 4.3.3 偏微数 ===== | ||
| + | |||
| + | 図4-8の出し方がわからなかったので調査。 | ||
| + | |||
| + | <code python> | ||
| + | |||
| + | def function_2(x): | ||
| + | return x[0]**2 + x[1]**2 | ||
| + | # return np.sum(x**2) | ||
| + | | ||
| + | |||
| + | import matplotlib.pylab as plt | ||
| + | from mpl_toolkits.mplot3d import Axes3D | ||
| + | |||
| + | # Figureと3DAxeS | ||
| + | fig = plt.figure(figsize = (5, 5)) | ||
| + | ax = fig.add_subplot(111, projection="3d") | ||
| + | |||
| + | # (x,y)データを作成 | ||
| + | x = np.arange(-1.0, 1.0, 0.1) | ||
| + | y = np.arange(-1.0, 1.0, 0.1) | ||
| + | |||
| + | # 格子点を作成 | ||
| + | X, Y = np.meshgrid(x, y) | ||
| + | |||
| + | # 高度の計算式 | ||
| + | Z = function_2(np.array([X,Y])) | ||
| + | |||
| + | # 曲面を描画 | ||
| + | ax.plot_surface(X, Y, Z, cmap = "summer") | ||
| + | |||
| + | plt.show() | ||
| + | |||
| + | </code> | ||
| + | |||
| + | {{:pasted:20210313-122642.png}} | ||