首页 > 解决方案 > 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' 外部函数

请帮忙

问候

标签: pythonubuntufor-looptensorflowsyntax-error

解决方案


__main__不是一个“函数”,因为你可以从中返回一些东西。

你想做什么,为什么要回来?


推荐阅读