質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

440閲覧

keras モデルの可視化ができない

mamagauro

総合スコア12

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/01/08 02:57

https://gist.github.com/adash333/9a5f1df82169c3dd7c9218111d4cbd05
のサイトを写経していますが、モデルの可視化の部分でエラーがでて行き詰ってしまいました。

入力データ

1 # original code from fruit.py @ http://qiita.com/hiroeorz@github/items/ecb39ed4042ebdc0a957 2 3 from keras.models import Sequential 4 from keras.layers import Activation, Dense, Dropout 5 from keras.utils.np_utils import to_categorical 6 from keras.optimizers import Adagrad 7 from keras.optimizers import Adam 8 import numpy as np 9 from PIL import Image 10 import os 11 12 # 学習用のデータを作る. 13 image_list = [] 14 label_list = [] 15 16 # ./data/train 以下のorange,appleディレクトリ以下の画像を読み込む。 17 for dir in os.listdir("data/train"): 18 if dir == ".DS_Store": 19 continue 20 21 dir1 = "data/train/" + dir 22 label = 0 23 24 if dir == "apple": # appleはラベル0 25 label = 0 26 elif dir == "orange": # orangeはラベル1 27 label = 1 28 29 for file in os.listdir(dir1): 30 if file != ".DS_Store": 31 # 配列label_listに正解ラベルを追加(りんご:0 オレンジ:1) 32 label_list.append(label) 33 filepath = dir1 + "/" + file 34 # 画像を5x5pixelに変換し、1要素が[R,G,B]3要素を含む配列の5x5の2次元配列として読み込む。 35 # [R,G,B]はそれぞれが0-255の配列。 36 image = np.array(Image.open(filepath).resize((5, 5))) 37 print(filepath) 38 # 配列を変換し、[[Redの配列],[Greenの配列],[Blueの配列]] のような形にする。 39 image = image.transpose(2, 0, 1) 40 # さらにフラットな1次元配列に変換。最初の1/3はRed、次がGreenの、最後がBlueの要素がフラットに並ぶ。 41 image = image.reshape(1, image.shape[0] * image.shape[1] * image.shape[2]).astype("float32")[0] 42 # 出来上がった配列をimage_listに追加。 43 image_list.append(image / 255.) 44 45 # kerasに渡すためにnumpy配列に変換。 46 image_list = np.array(image_list) 47 48 # ラベルの配列を1と0からなるラベル配列に変更 49 # 0 -> [1,0], 1 -> [0,1] という感じ。 50 Y = to_categorical(label_list) 51 52 # モデルを生成してニューラルネットを構築 53 model = Sequential() 54 model.add(Dense(200, input_dim=75)) 55 model.add(Activation("relu")) 56 model.add(Dropout(0.2)) 57 58 model.add(Dense(200)) 59 model.add(Activation("relu")) 60 model.add(Dropout(0.2)) 61 62 model.add(Dense(2)) 63 model.add(Activation("softmax")) 64 65 # オプティマイザにAdamを使用 66 opt = Adam(lr=0.001) 67 # モデルをコンパイル 68 model.compile(loss="categorical_crossentropy", optimizer=opt, metrics=["accuracy"]) 69 # 学習を実行。10%はテストに使用。 70 model.fit(image_list, Y, nb_epoch=500, batch_size=100, validation_split=0.1) 71 72 # テスト用ディレクトリ(./data/train/)の画像でチェック。正解率を表示する。 73 total = 0. 74 ok_count = 0. 75 76 for dir in os.listdir("data/train"): 77 if dir == ".DS_Store": 78 continue 79 80 dir1 = "data/test/" + dir 81 label = 0 82 83 if dir == "apple": 84 label = 0 85 elif dir == "orange": 86 label = 1 87 88 for file in os.listdir(dir1): 89 if file != ".DS_Store": 90 label_list.append(label) 91 filepath = dir1 + "/" + file 92 image = np.array(Image.open(filepath).resize((5, 5))) 93 print(filepath) 94 image = image.transpose(2, 0, 1) 95 image = image.reshape(1, image.shape[0] * image.shape[1] * image.shape[2]).astype("float32")[0] 96 result = model.predict_classes(np.array([image / 255.])) 97 print("label:", label, "result:", result[0]) 98 99 total += 1. 100 101 if label == result[0]: 102 ok_count += 1. 103 104 print("seikai: ", ok_count / total * 100, "%") 105 106 # モデルの可視化 107 from IPython.display import SVG 108 from keras.utils.vis_utils import model_to_dot 109 110 SVG(model_to_dot(model).create(prog='dot', format='svg'))

エラーメッセージ

--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) ~\AppData\Local\Continuum\anaconda3\envs\keras_tensor_py36_clone\lib\site-packages\pydot-1.2.3-py3.6.egg\pydot.py in create(self, prog, format) 1877 shell=False, -> 1878 stderr=subprocess.PIPE, stdout=subprocess.PIPE) 1879 except OSError as e: ~\AppData\Local\Continuum\anaconda3\envs\keras_tensor_py36_clone\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors) 708 errread, errwrite, --> 709 restore_signals, start_new_session) 710 except: ~\AppData\Local\Continuum\anaconda3\envs\keras_tensor_py36_clone\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session) 996 os.fspath(cwd) if cwd is not None else None, --> 997 startupinfo) 998 finally: FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。 During handling of the above exception, another exception occurred: Exception Traceback (most recent call last) <ipython-input-17-e2b5293eba2b> in <module> ----> 1 SVG(model_to_dot(model).create(prog='dot', format='svg')) ~\AppData\Local\Continuum\anaconda3\envs\keras_tensor_py36_clone\lib\site-packages\keras\utils\vis_utils.py in model_to_dot(model, show_shapes, show_layer_names, rankdir) 53 from ..models import Sequential 54 ---> 55 _check_pydot() 56 dot = pydot.Dot() 57 dot.set('rankdir', rankdir) ~\AppData\Local\Continuum\anaconda3\envs\keras_tensor_py36_clone\lib\site-packages\keras\utils\vis_utils.py in _check_pydot() 24 # Attempt to create an image of a blank graph 25 # to check the pydot/graphviz installation. ---> 26 pydot.Dot.create(pydot.Dot()) 27 except OSError: 28 raise OSError( ~\AppData\Local\Continuum\anaconda3\envs\keras_tensor_py36_clone\lib\site-packages\pydot-1.2.3-py3.6.egg\pydot.py in create(self, prog, format) 1881 raise Exception( 1882 '"{prog}" not found in path.'.format( -> 1883 prog=prog)) 1884 else: 1885 raise Exception: "dot.exe" not found in path.

対処方法をご教示願います。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

以下と同じ操作で本体をインストールしてください。

https://teratail.com/questions/166374

投稿2019/01/08 03:13

hayataka2049

総合スコア30933

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mamagauro

2019/01/11 06:22

ご回答ありがとうございます。ご指示いただいた内容を実施したところ解決いたしました。ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問