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

ValueError: Traceback (most recent call last) #32

Open kjayn opened 1 year ago

kjayn commented 1 year ago
# Create our model (returns a compiled model)
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)

ValueError: decay is deprecated in the new Keras optimizer, pleasecheck the docstring for valid arguments, or use the legacy optimizer, e.g., tf.keras.optimizers.legacy.SGD.

how to fix this?

MAHENDRA9535 commented 1 year ago
# Create our model (returns a compiled model)
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)

ValueError: decay is deprecated in the new Keras optimizer, pleasecheck the docstring for valid arguments, or use the legacy optimizer, e.g., tf.keras.optimizers.legacy.SGD.

how to fix this?

use this code instead:

this is the import statements you need to add

import tensorflow as tf import keras from keras.models import Sequential, Model from keras.layers import Conv2D, Flatten, MaxPooling2D, Dense, Input, Reshape, Concatenate, GlobalAveragePooling2D, BatchNormalization, Dropout, Activation, GlobalMaxPooling2D from keras.utils import Sequence

this is the functional code used to create the model

def create_ST_layer(input_shape = (64, 128, 3)): input_img = Input(shape=input_shape) model = Conv2D(48, kernel_size=(5, 5), input_shape = input_shape, strides = (1, 1), activation = "relu")(input_img) model = MaxPooling2D(pool_size=(2, 2), strides = (2, 2))(model) model = Conv2D(32, kernel_size=(5, 5), strides = (1, 1), activation = "relu")(model) model = MaxPooling2D(pool_size=(2, 2), strides = (2, 2))(model) model = Dense(50, activation = "relu")(model) model = Dense(6)(model) model = tf.keras.Model(inputs=input_img, outputs= model) return model

to print the summary

model = create_ST_layer() model.summary()

Hope this helps!!!!

MrIzzat commented 5 months ago

The best solution I found was to modify the simpsons.py file as stated in the answer here: https://stackoverflow.com/a/75951851/17870878.