david8862 / keras-YOLOv3-model-set

end-to-end YOLOv4/v3/v2 object detection pipeline, implemented on tf.keras with different technologies
MIT License
640 stars 222 forks source link

could not parse the source code: "yolo_loss": lambda y_true, y_pred: y_pred}) #123

Open tricoffee opened 4 years ago

tricoffee commented 4 years ago

Cause: could not parse the source code:

"yolo_loss": lambda y_true, y_pred: y_pred})

This error may be avoided by creating the lambda in a standalone statement.

To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert

emielsteerneman commented 3 years ago

Putting it into a single line seems to fix the issue. yolo3/model.py:266 model.compile(optimizer=optimizer, loss={'yolo_loss': lambda y_true, y_pred: y_pred})

vse-motec commented 3 years ago

Hello all, the suggestion of @emielsteerneman helped me to get rid of the warning, thank you for that. I am trying to understand this piece of code, maybe someone can help me.

  1. The lambda itself seems to be kind of useless: it gets two arguments and returns the second. Why does this make sense here?
  2. How does this lambda relate to the actual loss function defined as Lambda-Layer a few lines above? Obviously, there is some kind of name lookup an the name "yolo_loss". But why can't I then just pass the name "yolo_loss" as "loss" argument to model.compile and why do I need the seemingly useless lambda expression?
  3. In my (naive) understanding, passing "loss" argument with this lambda overwrites the name "yolo_loss". But this seems not to be the case, why?

Thanks in advance for any help on understanding this piece of code.