1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Return in Python fails for Tensorflow Processing Code [duplicate]

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    When I try this code in Python 2.7:

    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, results)
    age[j]=labels
    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


    I get an error that says: SyntaxError: 'return' outside function. What is wrong, and how can I fix it?

    Continue reading...

Compartilhe esta Página