0
私は現在、アプリケーションで訓練されたモデルを使用しようとしています。アプリケーションでtflearn訓練モデルを使用するにはどうすればよいですか?
私はthis codeを使用してLSTMモデルで米国の都市名を生成しています。コードは正常に動作し、私は都市名を取得することができます。
今はモデルを保存しようとしていますので、もう一度モデルをトレーニングせずに別のアプリケーションで読み込むことができます。ここで
が私の基本的なアプリケーションのコードです:
from __future__ import absolute_import, division, print_function
import os
from six import moves
import ssl
import tflearn
from tflearn.data_utils import *
path = "US_cities.txt"
maxlen = 20
X, Y, char_idx = textfile_to_semi_redundant_sequences(
path, seq_maxlen=maxlen, redun_step=3)
# --- Create LSTM model
g = tflearn.input_data(shape=[None, maxlen, len(char_idx)])
g = tflearn.lstm(g, 512, return_seq=True, name="lstm1")
g = tflearn.dropout(g, 0.5, name='dropout1')
g = tflearn.lstm(g, 512, name='lstm2')
g = tflearn.dropout(g, 0.5, name='dropout')
g = tflearn.fully_connected(g, len(char_idx), activation='softmax', name='fc')
g = tflearn.regression(g, optimizer='adam', loss='categorical_crossentropy',
learning_rate=0.001)
# --- Initializing model and loading
model = tflearn.models.generator.SequenceGenerator(g, char_idx)
model.load('myModel.tfl')
print("Model is now loaded !")
#
# Main Application
#
while(True):
user_choice = input("Do you want to generate a U.S. city names ? [y/n]")
if user_choice == 'y':
seed = random_sequence_from_textfile(path, 20)
print("-- Test with temperature of 1.5 --")
model.generate(20, temperature=1.5, seq_seed=seed, display=True)
else:
exit()
そして、ここでは、私は出力として得るものです:残念ながら
Do you want to generate a U.S. city names ? [y/n]y
-- Test with temperature of 1.5 --
rk
Orange Park AcresTraceback (most recent call last):
File "App.py", line 46, in <module>
model.generate(20, temperature=1.5, seq_seed=seed, display=True)
File "/usr/local/lib/python3.5/dist-packages/tflearn/models/generator.py", line 216, in generate
preds = self._predict(x)[0]
File "/usr/local/lib/python3.5/dist-packages/tflearn/models/generator.py", line 180, in _predict
return self.predictor.predict(feed_dict)
File "/usr/local/lib/python3.5/dist-packages/tflearn/helpers/evaluator.py", line 69, in predict
o_pred = self.session.run(output, feed_dict=feed_dict).tolist()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 717, in run
run_metadata_ptr)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 894, in _run
% (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (1, 25, 61) for Tensor 'InputData/X:0', which has shape '(?, 20, 61)'
形状は時に変更された理由を、私は見ることができません私のアプリでgenerate()を使用しています。誰も私がこの問題を解決するのを助けることができますか?
はウィリアム解決しよう
これはあなたの質問を完全には解決しませんが、 'sef_maxlen = 20'を' tflearn.models.generator.SequenceGenerator'に追加しようとすることはできますか?私は '25 'がこのコンストラクタパラメータから来たと思います。 – sygi
こんにちは、sygi、あなたの応答をありがとう、遅く返事を申し訳ありません。私はseq_maxlenを変更し、形状の問題は修正されました!しかし、あなたが言ったように、完全には機能していません...生成される名前はまったく新しいものではありません。私はコンストラクタにcheckpoint_pathを追加しようとしましたが、何も変更しませんでした。 –