2017-07-14 41 views
1
# restore all of our data structures 
import pickle 
import tflearn 
import tensorflow as tf 
import random 
... 
# load our saved model 
model.load('./model.tflearn') 

def clean_up_sentence(sentence): 
    # tokenize the pattern 
    sentence_words = nltk.word_tokenize(sentence) 
    # stem each word 

我的错误Tflearn问题在model.load

$ python wrapper.py 

Scipy not supported! 
Traceback (most recent call last): 
    File "wrapper.py", line 18, in <module> 
    model.load('./model.tflearn') 
NameError: name 'model' is not defined 

任何帮助吗?

This is my directory

和我的模型写的代码看起来像

model.fit(train_x, train_y, n_epoch=1000, batch_size=8, show_metric=True) 
model.save('model.tflearn') 

我使用tflearn开发一个聊天机器人,我训练的模型和保存的模型,但是当我加载一遍,然后它抛出一个错误,无论是在同一目录下的Python文件和模型在同一目录太..

+1

您没有声明变量'model'。在加载任何内容之前,您需要先定义“model”是什么。例如。 'model = DNN(网络)'。请参阅(http://tflearn.org/getting_started/)下的“培训,评估和预测”一个示例。 – Flomp

回答

1
net = tflearn.input_data(shape=[None, len(train_x[0])]) 
net = tflearn.fully_connected(net, 8) 
net = tflearn.fully_connected(net, 8) 
net = tflearn.fully_connected(net, len(train_y[0]), activation='softmax') 
net = tflearn.regression(net) 
model = tflearn.DNN(net, tensorboard_dir='tflearn_logs') 
# load our saved model 
model.load('./model.tflearn') 

我忘了提及的变量模型和本作的埃罗r弹出。

+1

尽管此代码片段可能会解决问题,但[包括解释](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)确实有助于提高帖子的质量。请记住,您将来会为读者回答问题,而这些人可能不知道您的代码建议的原因。也请尽量不要用解释性注释来挤占代码,这会降低代码和解释的可读性! –