jasmcaus / opencv-course

Learn OpenCV in 4 Hours - Code used in my Python and OpenCV course on freeCodeCamp.
https://youtu.be/oXlwWbU8l2o
MIT License
1.11k stars 955 forks source link

Unable to create model #4

Closed VibhuAg closed 3 years ago

VibhuAg commented 3 years ago

I got to the point in the course where I was instructed to create a model using this code: model = canaro.models.createSimpsonsModel(IMG_SIZE=IMG_SIZE, channels=channels, output_dim=len(characters), loss='binary_crossentropy', decay=1e-7, learning_rate=0.001, momentum=0.9, nesterov=True)

But I received this error: `--------------------------------------------------------------------------- TypeError Traceback (most recent call last)

in 2 model = canaro.models.createSimpsonsModel(IMG_SIZE=IMG_SIZE, channels=channels, output_dim=len(characters), 3 loss='binary_crossentropy', decay=1e-7, learning_rate=0.001, momentum=0.9, ----> 4 nesterov=True) TypeError: createSimpsonsModel() got an unexpected keyword argument 'loss'`
jasmcaus commented 3 years ago

Hi @VibhuAg! Thanks for bringing this to my attention. Can you confirm which version of canaro you are on and whether upgrading to v1.0.9 helps fix this issue? You can do a simple pip install --upgrade canaro

VibhuAg commented 3 years ago

Hi @jasmcaus, this fixed the initial value error but now I am getting a different value error: '--------------------------------------------------------------------------- ValueError Traceback (most recent call last)

in 2 model = canaro.models.createSimpsonsModel(IMG_SIZE=IMG_SIZE, channels=channels, output_dim=len(characters), 3 loss='binary_crossentropy', decay=1e-7, learning_rate=0.001, momentum=0.9, ----> 4 nesterov=True) /opt/conda/lib/python3.7/site-packages/canaro/models/simpsons.py in createSimpsonsModel(IMG_SIZE, channels, output_dim, loss, decay, learning_rate, momentum, nesterov) 42 output = Dense(output_dim, activation='softmax', name='output_node')(model) 43 ---> 44 model = Model(inputs=input, outputs=output) 45 46 optimizer = SGD(lr=learning_rate, decay=decay, momentum=momentum, nesterov=nesterov) /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in __new__(cls, *args, **kwargs) 240 # Functional model 241 from tensorflow.python.keras.engine import functional # pylint: disable=g-import-not-at-top --> 242 return functional.Functional(*args, **kwargs) 243 else: 244 return super(Model, cls).__new__(cls, *args, **kwargs) /opt/conda/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs) 455 self._self_setattr_tracking = False # pylint: disable=protected-access 456 try: --> 457 result = method(self, *args, **kwargs) 458 finally: 459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/functional.py in __init__(self, inputs, outputs, name, trainable) 113 # 'arguments during initialization. Got an unexpected argument:') 114 super(Functional, self).__init__(name=name, trainable=trainable) --> 115 self._init_graph_network(inputs, outputs) 116 117 @trackable.no_automatic_dependency_tracking /opt/conda/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs) 455 self._self_setattr_tracking = False # pylint: disable=protected-access 456 try: --> 457 result = method(self, *args, **kwargs) 458 finally: 459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/functional.py in _init_graph_network(self, inputs, outputs) 142 base_layer_utils.create_keras_history(self._nested_outputs) 143 --> 144 self._validate_graph_inputs_and_outputs() 145 146 # A Network does not create weights of its own, thus it is already /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/functional.py in _validate_graph_inputs_and_outputs(self) 637 'must come from `tf.keras.Input`. ' 638 'Received: ' + str(x) + --> 639 ' (missing previous layer metadata).') 640 # Check that x is an input tensor. 641 # pylint: disable=protected-access ValueError: Input tensors to a Functional must come from `tf.keras.Input`. Received: > (missing previous layer metadata).'
jasmcaus commented 3 years ago

On further inspection, this seemed to be from a bug with canaro. I've fixed it in v1.1.0, so hopefully, things should work fine now. You may upgrade your version of canaro via a pip install --upgrade canaro.

VibhuAg commented 3 years ago

Thanks!