Skip to content

[Bug] after I saved rnet to saved model. when I try to load, get errors. #138

@iysheng

Description

@iysheng

Describe the bug
I saved rnet mode to tensorflow saved model in red_rnet dir success.
But when I try to load this saved model ,I get errors as

red_rnet has saved before
Traceback (most recent call last):
  File "/home/yjoy/gProjects/mtcnn/./test00.py", line 22, in <module>
    detector = MTCNN(device="CPU:0")
  File "/home/yjoy/gProjects/mtcnn/mtcnn/mtcnn.py", line 61, in __init__
    self._stages = [stage() if isinstance(stage, type) else stage for stage in stages]
  File "/home/yjoy/gProjects/mtcnn/mtcnn/mtcnn.py", line 61, in <listcomp>
    self._stages = [stage() if isinstance(stage, type) else stage for stage in stages]
  File "/home/yjoy/gProjects/mtcnn/mtcnn/stages/stage_rnet.py", line 65, in __init__
    model = tf.keras.models.load_model('red_rnet/', compile=False)
  File "/home/yjoy/.conda/envs/mtcnn_tf12/lib/python3.10/site-packages/keras/saving/saving_api.py", line 212, in load_model
    return legacy_sm_saving_lib.load_model(
  File "/home/yjoy/.conda/envs/mtcnn_tf12/lib/python3.10/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/yjoy/.conda/envs/mtcnn_tf12/lib/python3.10/site-packages/keras/initializers/initializers.py", line 171, in __call__
    return tf.zeros(shape, dtype)
ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.

Besides, I use the same way to save pnet saved mode, and load the saved mode success.

the code with releate as

+            model = RNet()
+            model.build()  # Building the RNet model
+            model.set_weights(load_weights(weights))  # Load pre-trained weights
+            print(model, model.summary(), "\nsummary done of rnet")
+            # for save mode, use dummy_input here
+            dummy_input=np.random.rand(1,24,24,3)
+            model(dummy_input)
+            #  model.save("red_rnet/", include_optimizer=True)
+            model.save("red_rnet/")

the load code as

model = tf.keras.models.load_model('red_rnet/', compile=False)

To Reproduce
save rnet mode, and then load the mode.

Expected behavior
load rnet model success.

Screenshots

Image

Environment (please complete the following information):

  • OS: [e.g., Windows, macOS, Linux]
  • Python version: [3.10]
  • Version of the project: [master version]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions