see-rnnというライブラリを利用しようとしているのですが、GitのサンプルのPythonコードは動作するのですが、このライブラリを自作のスクリプトに埋め込んだところ、
from see_rnn import get_rnn_gradients, show_features_1D, show_features_2D
ImportError: cannot import name 'get_rnn_gradients' from 'see_rnn' (C:\Users\username\AppData\Local\Programs\Python\Python37\lib\site-packages\see_rnn_init_.py)
というエラーメッセージが出て動作しません。
#seernn from keras.layers import Input, LSTM from keras.models import Model from keras.optimizers import Adam from see_rnn import get_rnn_gradients, show_features_1D, show_features_2D from see_rnn import show_features_0D
このfrom see_rnnの行でエラーが発生します。
よろしくお願いいたします。
サンプルは
import numpy as np from keras.layers import Input, LSTM from keras.models import Model from keras.optimizers import Adam from see_rnn import get_rnn_gradients, show_features_1D, show_features_2D from see_rnn import show_features_0D def make_model(rnn_layer, batch_shape, units): ipt = Input(batch_shape=batch_shape) x = rnn_layer(units, activation='tanh', return_sequences=True)(ipt) out = rnn_layer(units, activation='tanh', return_sequences=False)(x) model = Model(ipt, out) model.compile(Adam(4e-3), 'mse') return model def make_data(batch_shape): return np.random.randn(*batch_shape), \ np.random.uniform(-1, 1, (batch_shape[0], units)) def train_model(model, iterations, batch_shape): x, y = make_data(batch_shape) for i in range(iterations): model.train_on_batch(x, y) print(end='.') # progbar if i % 40 == 0: x, y = make_data(batch_shape) units = 6 batch_shape = (16, 100, 2*units) model = make_model(LSTM, batch_shape, units) train_model(model, 300, batch_shape) x, y = make_data(batch_shape) grads_all = get_rnn_gradients(model, x, y, layer_idx=1) # return_sequences=True grads_last = get_rnn_gradients(model, x, y, layer_idx=2) # return_sequences=False show_features_1D(grads_all, n_rows=2, show_xy_ticks=[1,1]) show_features_2D(grads_all, n_rows=8, show_xy_ticks=[1,1], norm=(-.01, .01)) show_features_0D(grads_last)
です。
追記:
https://github.com/OverLordGoldDragon/see-rnn/issues/9
にある通り、不具合のようです。
あなたの回答
tips
プレビュー