Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variable shape and value shape are incompatible #10

Open
davidlehrian opened this issue May 29, 2022 · 0 comments
Open

variable shape and value shape are incompatible #10

davidlehrian opened this issue May 29, 2022 · 0 comments

Comments

@davidlehrian
Copy link

davidlehrian commented May 29, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant