python - TensorFlow 处理代码在 Linux Mint 上的 Python 中返回失败
问题描述
我的python代码给出了以下问题:-
if __name__ == "__main__":
file_name = "tensorflow/examples/label_image/data/grace_hopper.jpg"
...
with tf.Session(graph=graph) as sess:
results = sess.run(output_operation.outputs[0], {
input_operation.outputs[0]: t
})
results = np.squeeze(results)
top_k = results.argsort()[-5:][::-1]
labels = load_labels(label_file)
j=0
for i in top_k:
print(labels[i], results[i])
age[j]=labels[i]
j=j+1
if age[0] == "youngadult":
t = 0
elif age[0] == "youth":
t = 1
elif age[0] == "adult":
t = 2
elif age[0] == "seniors":
t = 3
elif age[0] == "children":
t = 4
else:
t = 5
return t
PS Python - Python 2.7.15 :: Anaconda, Inc.
Linux- Mint18.3 肉桂 64 位
肉桂版 - 3.6.7
处理器 - AMD Ryzen5 1600 六核处理器 X 6
内存 - 7.8GiB
硬盘 - 952.7GB
显卡 - NVIDIA Corporation 设备 1c82
错误 - SyntaxError: 'return' 外部函数
请帮忙
问候
解决方案
__main__
不是一个“函数”,因为你可以从中返回一些东西。
你想做什么,为什么要回来?
推荐阅读
- android - DiffUtil 重绘 ListAdapter Kotlin 中的所有项目
- google-cloud-platform - 有什么方法可以使用一些谷歌云 java 客户端获取“令牌”?
- python - Python .exe 文件在双击时不会运行,但在通过 cmd 运行时可以运行
- sql - 如何将带有逗号的sql列格式化为数字格式
- python - 运行两个电机的树莓派
- strapi - 错误:无法使用来自另一个模块或领域的 GraphQLObjectType“查询”
- git - 从给定文件 git 中的提交哈希中删除更改
- node.js - gtk printOperation 没有对话框
- javascript - 使用 HTML/Javascript 将数字编码为字母
- javascript - req.body 在发布到 API 时返回格式奇怪的对象