У меня есть простое приложение для работы с колбами для модели с тензорным потоком. Насколько я знаю, я сгладил все другие ошибки. Но когда приходит время запустить приложение, я получаю эту ошибку:
RuntimeError: Working outside of request context.
Traceback (most recent call last):
File "app.py", line 61, in <module>
if request.args:
File "/home/m0oN/.local/lib/python3.5/site-packages/werkzeug/local.py",
line 347, in __getattr__
return getattr(self._get_current_object(), name)
File "/home/m0oN/.local/lib/python3.5/site-packages/werkzeug/local.py",
line 306, in _get_current_object
return self.__local()
File "/home/m0oN/.local/lib/python3.5/site-packages/flask/globals.py",
line 37, in _lookup_req_object
raise RuntimeError(_request_ctx_err_msg)
RuntimeError: Working outside of request context.
This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.
Я думаю, что главная проблема заключается здесь:
if __name__ == '__main__':
file_name = 'steph.jpg'
model_file = 'thotornot_graph.pb'
lable_file = 'retrained_labels.txt'
input_height = 299
input_width = 299
input_mean = 128
input_std = 128
input_layer = "Mul"
output_layer = "final_result"
if request.args:
file_name = request.args
graph = load_graph(model_file)
t = read_tensor_from_image_file(file_name,
input_height=input_height,
input_width=input_width,
input_mean=input_mean,
input_std=input_std)
input_name = 'import/' + input_layer
output_name = 'import/' + output_layer
input_operation = graph.get_operation_by_name(input_name);
output_operation = graph.get_operation_by_name(output_name);
with tf.Session(graph=graph) as sess:
start = time.time()
results = sess.run(output_operation.outputs[0],
{input_operation.outputs[0]: t})
end = time.time()
results = np.squeeze(results)
top_k = results.argsort()[-5:][::-1]
lables = load_lables(lable_file)
print('\nEvaluation time (1-image): {:.3f}s\n'.format(end-start))
for i in top_k:
print(lables[i], results[i])
app.run(localhost, 8081)
Ссылка на мой полный код находится здесь https://paste.ee/p/ztYKg
У кого-нибудь есть решение?