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

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

新規登録して質問してみよう
ただいま回答率
85.47%
Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

Keras

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

Python 3.x

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

Q&A

解決済

1回答

2308閲覧

Kerasで中間層の値の表示

Bonziri

総合スコア16

Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

Keras

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

Python 3.x

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

0グッド

0クリップ

投稿2019/07/30 10:09

kerasのチュートリアルでAEの勉強中です.
圧縮したデータの値(中間層の値)を見ようとしたのですが,どうすれば見れるのかわかりません.

モデルのコード

ここのencodedの値を見たいです.

#モデルの生成 input_img = Input(shape=(100, 100, 3)) # adapt this if using `channels_first` image data format x = Conv2D(16, (10, 10), padding='same')(input_img) x = BatchNormalization()(x) x = Activation('relu')(x) x = MaxPooling2D((2, 2), padding='same')(x) x = Conv2D(8, (10, 10), padding='same')(x) x = BatchNormalization()(x) x = Activation('relu')(x) x = MaxPooling2D((2, 2), padding='same')(x) x = Conv2D(8, (10, 10), padding='same')(x) x = BatchNormalization()(x) x = Activation('relu')(x) x = MaxPooling2D((5, 5), padding='same')(x) x = Flatten()(x) encoded = Dense(20, activation='sigmoid')(x) x = Dense(200, activation='sigmoid')(encoded) x = Reshape((5, 5, 8))(x) # at this point the representation is (4, 4, 8) i.e. 128-dimensional x = Conv2D(8, (10, 10),padding='same')(x) x = BatchNormalization()(x) x = Activation('relu')(x) x = UpSampling2D((5, 5))(x) x = Conv2D(8, (10, 10),padding='same')(x) x = BatchNormalization()(x) x = Activation('relu')(x) x = UpSampling2D((2, 2))(x) x = Conv2D(16, (10, 10),padding='same')(x) x = BatchNormalization()(x) x = Activation('relu')(x) x = UpSampling2D((2, 2))(x) decoded = Conv2D(3, (10, 10), activation='sigmoid', padding='same')(x) autoencoder = Model(input_img, decoded) autoencoder.compile(optimizer='adam', loss='mean_squared_error')

試したこと

autoencoder.save_weights('autoencoder0730.json') from keras.models import model_from_json json_string = open('autoencoder0730.json', 'r' ,encoding="utf-8").read() data = json.load(json_string) print(data)

エラー
utf-8以外の文字は無視するようなコードも書いてみましたがダメでした.

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte


https://keras.io/ja/getting-started/faq/#_7
中間レイヤーの出力を得るには?というトピックがあるのですが,自分のコードに合うように書き直す方法がわかりません.

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

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

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

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

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

tiitoi

2019/07/30 10:29

動かして確認したいので、コード全体を貼ることはできますか?
Bonziri

2019/08/01 07:12

コメントありがとうございます 無事解決することができました.
guest

回答1

0

ベストアンサー

python

1autoencoder.save_weights('autoencoder0730.json') 2from keras.models import model_from_json 3json_string = open('autoencoder0730.json', 'r' ,encoding="utf-8").read() 4data = json.load(json_string) 5 6new_model = tf.keras.Model( 7 inputs=data.input, outputs=data.get_layer("encodedの層の名前").output() 8)

こうしておけば、

python

1a = new_model.predict(input_img)

のように、predictから見れます。

encoded=Dense(20, activation='sigmoid')(x)で定義されている層の名前が何かはautoencode.summary()から見れます。

投稿2019/07/30 14:09

Yhaya

総合スコア439

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

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

Bonziri

2019/07/31 01:39

回答ありがとうございます UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte というエラーでました. 元々,encoding="utf-8"がないコードで下記のようなエラーがでていたので書きかえたのですが,この場合どうすればよいのでしょうか UnicodeDecodeError: 'cp932' codec can't decode byte 0x88 in position 80: illegal multibyte sequence
Bonziri

2019/08/01 07:12

autoencoder.save_weights('autoencoder0801.h5') で保存したあと, autoencoder.load_weights('autoencoder0801.h5') encoder = Model(input_img, encoded) encoded_imgs = encoder.predict(x_train) print(encoded_imgs) とすると期待した形の値を得ることができました. 上記のコメントがさんこうに参考になりました. ありがとうございました.
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問