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

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

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

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

Anaconda

Anacondaは、Python本体とPythonで利用されるライブラリを一括でインストールできるパッケージです。環境構築が容易になるため、Python開発者間ではよく利用されており、商用目的としても利用できます。

Python

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

pip

pipとは、Pythonを用いて書かれているパッケージソフトのインストールや管理を行うためのパッケージマネジメントシステムです。pipを使う主なメリットは、コマンドラインインターフェースにて容易にPythonパッケージソフトをインストール可能だという点です。

Q&A

解決済

1回答

1704閲覧

Python3.6 Kerasの可視化をquiver-engineを用いて行いたい

kubo1216

総合スコア4

Keras

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

Anaconda

Anacondaは、Python本体とPythonで利用されるライブラリを一括でインストールできるパッケージです。環境構築が容易になるため、Python開発者間ではよく利用されており、商用目的としても利用できます。

Python

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

pip

pipとは、Pythonを用いて書かれているパッケージソフトのインストールや管理を行うためのパッケージマネジメントシステムです。pipを使う主なメリットは、コマンドラインインターフェースにて容易にPythonパッケージソフトをインストール可能だという点です。

0グッド

0クリップ

投稿2021/09/26 12:41

編集2021/09/26 13:58

前提・実現したいこと

オライリーの直感deeplerningを読みながらquiver-engineを使用し、localhostでデVGG16モデルの可視化を行おうとしています。

localhost:8000を開くと./sample_images内の画像が表示され画像を選択すると、Select a layerと表示されるのですが選択すべきレイヤーが表示されません。
本来であれば画面左にレイヤーが表示されるはずです。イメージ説明

下記のコードに「コマンドの構文が間違っています」と出ているのはこちらの質問にある通りmkdirコマンドの構文エラーであり./tmpを自作すれば問題ないのかなと思っています(違うかもしれません)。

KerasやTensorFlowについても素人で丸一日この問題が解決できず困っております。
質問も下手くそで恐縮ですが、何卒宜しくお願いします。

該当のソースコード

python

1>>> from keras.applications.vgg16 import VGG16 22021-09-26 20:44:16.997340: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found 32021-09-26 20:44:16.997606: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 4>>> from quiver_engine import server 5>>> model = VGG16() 62021-09-26 20:44:25.368588: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll 72021-09-26 20:44:25.394442: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties: 8pciBusID: 0000:01:00.0 name: GeForce GTX 1660 SUPER computeCapability: 7.5 9coreClock: 1.8GHz coreCount: 22 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 312.97GiB/s 102021-09-26 20:44:25.396509: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found 112021-09-26 20:44:25.398060: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found 122021-09-26 20:44:25.401379: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll 132021-09-26 20:44:25.403012: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll 142021-09-26 20:44:25.410150: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll 152021-09-26 20:44:25.411627: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found 162021-09-26 20:44:25.413387: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found 172021-09-26 20:44:25.413726: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. 18Skipping registering GPU devices... 192021-09-26 20:44:25.414365: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX2 20To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 212021-09-26 20:44:25.421323: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1e0c58bc420 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 222021-09-26 20:44:25.421614: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version 232021-09-26 20:44:25.422078: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix: 242021-09-26 20:44:25.422365: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263] 25>>> server.launch(model, input_folder='./sample_images', temp_folder='./tmp', port=8000) 26コマンドの構文が誤っています。 27Starting webserver from: C:\Users\kubo\anaconda3\envs\python_for_ch02\lib\site-packages\quiver_engine 28::1 - - [2021-09-26 20:44:30] "GET / HTTP/1.1" 304 173 0.001026 29::1 - - [2021-09-26 20:44:30] "GET /app.c1d3d21cfba8c1aabed6806773c8f0ba.css HTTP/1.1" 304 203 0.000997 30::1 - - [2021-09-26 20:44:30] "GET /vendor.280c5ce1d78077ee8d66.js HTTP/1.1" 304 193 0.000998 31::1 - - [2021-09-26 20:44:30] "GET /app.14b8092d6ea379715007.js HTTP/1.1" 304 190 0.000997 32::1 - - [2021-09-26 20:44:30] "GET /model HTTP/1.1" 200 10742 0.006952 33::1 - - [2021-09-26 20:44:30] "GET /inputs HTTP/1.1" 200 162 0.000000 34::1 - - [2021-09-26 20:44:30] "GET /input-file/cat.png HTTP/1.1" 304 170 0.000997 35::1 - - [2021-09-26 20:44:30] "GET /input-file/dog.png HTTP/1.1" 304 170 0.000998

補足情報(FW/ツールのバージョンなど)

環境:Windows10
Python3.6
Anaconda3で仮想環境を作成し、パッケージのインストールはpip install -r requirements-windows.txtで行いました。

keras==2.4.3 tensorflow==2.3.0 gevent==21.8.0 git+https://github.com/SnowMasaya/quiver h5py==2.10.0

試したこと

ここに至るまでにいくつかエラーが発生したためquiver_engineに手を加えています。

server.py

こちらを参考に変更を加えました。

python

1# from gevent.wsgi import WSGIServer 2from gevent.pywsgi import WSGIServer

file_utils.py

こちらを参考に変更を加えました。

python

1# from imageio import imwrite 2# ... 3# imsave(filename, deprocess_image(layer_outputs)) 4 5import imageio 6... 7 imageio.imwrite(filename, deprocess_image(layer_outputs)) 8

util.py

こちらを参考に変更を加えました。

python

1def get_input_config(model): 2 ''' 3 returns a tuple (inputDimensions, numChannels) 4 ''' 5 # return ( 6 # model.get_input_shape_at(0)[2:4], 7 # model.get_input_shape_at(0)[1] 8 # ) if K.image_data_format() == 'th' else ( 9 # # ) if K.image_dim_ordering() == 'th' else ( 10 # #tf ordering 11 # model.get_input_shape_at(0)[1:3], 12 # model.get_input_shape_at(0)[3] 13 # ) 14 return ( 15 model.get_config(0), 16 model.get_config(0) 17 ) if K.image_data_format() == 'th' else ( 18 #tf ordering 19 model.get_layer(index=0).get_config(), 20 model.get_layer(index=0).get_config() 21 )

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

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

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

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

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

kubo1216

2021/09/27 10:36

ご指摘ありがとうございます。 そちらのファイルで間違いありません。 恥ずかしながら試行錯誤中にバージョンを書き換え、そのまま戻し忘れたうえ書き換えたことすら忘れていたのだと思います。 正しいバージョンに戻していくつか修正を行ったところ動作するようになりました。 質問を閉じるため回答していただけないでしょうか。
guest

回答1

0

ベストアンサー

質問者さんが使ってる
version="0.1.4.1.4"
よりも新しそうな
version="0.1.4.1.5"

Quiver
をダウンロードして、コードを修正したら、当方のMac, Win 10のPythonで動きました

環境
Python 3.7
tensorflow 1.15.3
Keras 2.3.1

下記を修正しました

「file_utils.py」

python

1from scipy.misc import imsave

↓ 変更

python

1import imageio

 .

python

1 imsave(filename, deprocess_image(layer_outputs))

↓ 変更

python

1 imageio.imwrite(filename, deprocess_image(layer_outputs))

 
「imagenet_utils.py」

python

1 dim_ordering = K.image_dim_ordering() 2 assert dim_ordering in {'tf', 'th'}

↓ 変更

python

1 dim_ordering = K.image_data_format() 2 assert dim_ordering in {'channels_last', 'channel_first'}

 .

python

1 if dim_ordering == 'th':

↓ 変更

python

1 if dim_ordering == 'channel_first':

 
「layer_result_generators.py」

python

1 input=model.input, 2 output=model.get_layer(layer_name).output

↓ 変更

python

1 inputs=model.input, 2 outputs=model.get_layer(layer_name).output

 
「util.py」

python

1 return ( 2 model.get_input_shape_at(0)[2:4], 3 model.get_input_shape_at(0)[1] 4 ) if K.image_dim_ordering() == 'th' else ( 5 #tf ordering 6 model.get_input_shape_at(0)[1:3], 7 model.get_input_shape_at(0)[3] 8 )

↓ 変更

python

1 return ( 2 model.get_layer(index=0).get_config()["batch_input_shape"][0:3], 3 model.get_layer(index=0).get_config()["batch_input_shape"][3] 4 ) if K.image_data_format() == 'channel_first' else ( 5 #tf ordering 6 model.get_layer(index=0).get_config()["batch_input_shape"][0:3], 7 model.get_layer(index=0).get_config()["batch_input_shape"][3] 8 )

 .

python

1 image.img_to_array(image.load_img(input_path, target_size=target_shape, grayscale=grayscale)) / 255.0,

↓ 変更

python

1 image.img_to_array(image.load_img(input_path, target_size=(target_shape[1], target_shape[2]), grayscale=grayscale)) / 255.0,

 .

python

1 img = image.load_img(input_path, target_size=target_shape,

↓ 変更

python

1 img = image.load_img(input_path, target_size=(target_shape[1], target_shape[2]),

投稿2021/09/28 09:06

jbpb0

総合スコア7651

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

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

jbpb0

2021/09/28 10:06 編集

上記に加え、さらに keras ↓ 変更 tensorflow.keras import tensorflow as tf ↓ 変更 import tensorflow.compat.v1 as tf tf.disable_v2_behavior() を修正して、tensorflow 2.3で実行したら、質問の現象が再現しましたので、原因はtensorflow 1と2の違いによるものだと思います
kubo1216

2021/09/28 23:22

原因のと特定までしていただきありがとうございます。 私の方でも上記のバージョンでも試してみようと思います。 今後ともよろしくおねがいします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問