Skip to content

variable shape and value shape are incompatible #10

@davidlehrian

Description

@davidlehrian

Hello Moses,
I was following along on your posting https://towardsdatascience.com/train-image-recognition-ai-with-5-lines-of-code-8ed0bdd8d9ba and want to say great example code. I was able to get everything downloaded and start the training process but I don't have an nvidia card so it was going to take 4 days to create the model. So instead I downloaded the prebuilt model from the provided link and when I attempted to identify an image I get the following error:

Traceback (most recent call last):
  File "C:\Users\lehrian\Documents\GitHub\ImageAI\imageai\Classification\Custom\__init__.py", line 520, in loadModel
    model.load_weights(self.modelPath)
  File "C:\Users\lehrian\Envs\idenprof\lib\site-packages\tensorflow\python\keras\engine\training.py", line 2234, in load_weights
    hdf5_format.load_weights_from_hdf5_group(f, self.layers)
  File "C:\Users\lehrian\Envs\idenprof\lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py", line 710, in load_weights_from_hdf5_group
    K.batch_set_value(weight_value_tuples)
  File "C:\Users\lehrian\Envs\idenprof\lib\site-packages\tensorflow\python\util\dispatch.py", line 201, in wrapper
    return target(*args, **kwargs)
  File "C:\Users\lehrian\Envs\idenprof\lib\site-packages\tensorflow\python\keras\backend.py", line 3706, in batch_set_value
    x.assign(np.asarray(value, dtype=dtype(x)))
  File "C:\Users\lehrian\Envs\idenprof\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 891, in assign
    (tensor_name, self._shape, value_tensor.shape))
ValueError: Cannot assign to variable conv3_block1_0_conv/kernel:0 due to variable shape (1, 1, 256, 512) and value shape (512, 128, 1, 1) are incompatible

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\lehrian\Documents\GitHub\ImageAI\imagprof\FirstCustomImageRecognition.py", line 13, in <module>
    prediction.loadModel(num_objects=10)
  File "C:\Users\lehrian\Documents\GitHub\ImageAI\imageai\Classification\Custom\__init__.py", line 524, in loadModel
    raise ValueError("An error occured. Ensure your model file is a ResNet50 Model and is located in the path {}".format(self.modelPath))
ValueError: An error occured. Ensure your model file is a ResNet50 Model and is located in the path idenprof_061-0.7933.h5

In doing a search it seems this is due to a change in Tensorflow so I'm not sure if the model needs to be rebuilt or this can be fixed in code. I'm digging into the code now to see if I can make it work but wanted to let you know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions