niciBume / Cat_Prey_Analyzer

Cat Prey Image-Classification with deeplearning
MIT License
142 stars 21 forks source link

Loading Models #28

Open matthewkeck opened 1 month ago

matthewkeck commented 1 month ago

Hello,

Thank you for making this repository it has been really helpful. I have encountered an issue when trying to load the custom models I receive this error message.

Executing CatPreyAnalyzer
CatCamPy: /home/pi
Log Dir: /home/pi/Cat_Prey_Analyzer/log
/home/pi/tensorflow1/models/research
/home/pi/tensorflow1/models/research/object_detection
CNN is ready to go!
Traceback (most recent call last):
  File "/home/pi/Cat_Prey_Analyzer/cascade.py", line 724, in <module>
    sq_cascade = Sequential_Cascade_Feeder()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/Cat_Prey_Analyzer/cascade.py", line 75, in __init__
    self.base_cascade = Cascade()
                        ^^^^^^^^^
  File "/home/pi/Cat_Prey_Analyzer/cascade.py", line 417, in __init__
    self.pc_stage = PC_Stage()
                    ^^^^^^^^^^
  File "/home/pi/Cat_Prey_Analyzer/model_stages.py", line 273, in __init__
    self.pc_model = tf.keras.models.load_model(os.path.join(PC_models_dir, self.pc_model_name))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/codeProjects/myenv/lib/python3.11/site-packages/keras/src/saving/saving_api.py", line 183, in load_model
    return legacy_h5_format.load_model_from_hdf5(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/codeProjects/myenv/lib/python3.11/site-packages/keras/src/legacy/saving/legacy_h5_format.py", line 138, in load_model_from_hdf5
    load_weights_from_hdf5_group(f["model_weights"], model)
  File "/home/pi/codeProjects/myenv/lib/python3.11/site-packages/keras/src/legacy/saving/legacy_h5_format.py", line 357, in load_weights_from_hdf5_group
    raise ValueError(
ValueError: Layer count mismatch when loading weights from file. Model expected 1 layers, found 3 saved layers.

From my reading online it looks like there has been changes to how models have been saved and loaded in the past. Thank you for your time.

matthewkeck commented 1 month ago

Sorry I it looks like issue #27 has the fix.

picard1970 commented 3 weeks ago

Hi. I get the same error. Where can I find issue #27 for the resolution? KR Thomas

matthewkeck commented 3 weeks ago

its the first issue in the closed section. The #27 should be a link to it.

picard1970 commented 3 weeks ago

Found it. I am also using a Pi5. Will have to downgrade, I guess.

matthewkeck commented 3 weeks ago

If I remember right the guy in the issue had to downgrade. I am running a Pi4 and it works for me. It might be worth setting up a docker container.