ImageAI icon indicating copy to clipboard operation
ImageAI copied to clipboard

WARNING: tensorflow: Model failed to serialize as JSON. Ignoring... Layer YoloLayer has arguments in `__init__` and therefore must override `get_config`.

Open marbortoli opened this issue 3 years ago • 6 comments

Hello everyone, I'm trying to run a custom model detection as the example script with the hololens

"from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory (data_directory = "/content/hololens") trainer.setTrainConfig (object_names_array = ["hololens"], batch_size = 4, num_experiments = 100, train_from_pretrained_model = "/content/pretrained-yolov3.h5") trainer.trainModel()"

however, I always get this error message just after the first epochs: WARNING:tensorflow:Model failed to serialize as JSON. Ignoring... Layer YoloLayer has arguments in __init__ and therefore must override get_config. ... CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument. warnings.warn('Custom mask layers require a config and must override '

I don't understand how to fix it. Can someone help me? I'm running on tensorflow 2.7, VScode, CPU

Thanks a lot :)

marbortoli avatar Oct 19 '21 12:10 marbortoli

solved!

marbortoli avatar Oct 22 '21 08:10 marbortoli

Is this warning important and how did you fix it? @marbortoli

LucienMP avatar Nov 24 '21 16:11 LucienMP

hey! I was having issues running the code on my local computer.. so it was important to me,

I followed this issue here: https://stackoverflow.com/questions/61390089/ignoring-layers-with-arguments-in-init-must-override-get-config

I added the def get_config.... in my yolov3 script :)

marbortoli avatar Nov 25 '21 07:11 marbortoli

I'm having this issue too - It comes about when I run the simple training example (although I'm using a different dataset).

I think this issue - the warning regarding failing to serialize a json - and the issue with model evaluation (also resulting from running the object detection evaluation tutorial with the specified libraries) where it evaluates everything as zero might be related?

Based on the error messages alone, it looks like the model configuration might not be saved correctly, and then the evaluation cannot read it correctly.

gdubbs100 avatar Feb 24 '22 06:02 gdubbs100

I'm also having this issue, when you say that "it evaluates everything to zero" you mean the mAP score is zero after training right ? Also, I'm not sure if anybody else is having this issue but when I train my YoloV3 architecture and save the model, not all the epochs get saved for some reason. Is anybody else having said issue @gdubbs100 ?

Edwin-Aguirre92 avatar Mar 01 '22 23:03 Edwin-Aguirre92

@marbortoli which yolov3 script did you add with def get_config? Is it at /usr/local/lib/python3.7/dist-packages/imageai/Detection/YOLO/yolov3.py?

farizqinanda avatar Apr 14 '22 02:04 farizqinanda