HELLO, IAM HAVING THIS EROR, SOMEONE CAN HELP ME. ITS AIN IMAGGE CLASSIFIER,ALREADY CHECK THE NORMALIZATION AND DATA SIZE, IDK WHAT SI THE PROBLEM, IAM USING MOBILENETV2 FEATURE VECTOR FOR THE INPUT AND A DENSE LAYER AFTER.IAM USING VSCODE AND PYTHON, THE ERROR SAYS EXPECTED A DIMENSION OF 1 GOT 2
tensorflow.python.framework.errors_impl.InvalidArgumentError: Graph execution error:Detected at node predict/feature_vector/SpatialSqueeze defined at (most recent call last):<stack traces unavailable>Can not squeeze dim[1], expected a dimension of 1, got 2 [[{{node predict/feature_vector/SpatialSqueeze}}]] [Op:__inference_train_function_17547]
MY CODE IS HERE
#modelos\Scripts\activate(Activación mediante terminal deentorno virtual con tensorflow instalado)import osos.environ["TF_USE_LEGACY_KERAS"] = "1"import tensorflow as tfimport tensorflow_hub as hubimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.image as mpimg#Aumento de datos con ImageDataGenerator#Creación dataset generadordatagen = tf.keras.preprocessing.image.ImageDataGenerator(rescale= 1. / 255, #Normalización de datos 0-1rotation_range = 30,width_shift_range = 0.25,shear_range=15,zoom_range= [0.5, 1.5],)#Generadores para sets de entrenamiento y pruebasdata_gen_entrenamiento = datagen.flow_from_directory(directory =r'C:\Users\jguev\Desktop\Dataset\Train', target_size=(244,244), batch_size=32, shuffle=True)data_gen_pruebas = datagen.flow_from_directory(directory =r'C:\Users\jguev\Desktop\Dataset\Pruebas', target_size=(244,244), batch_size=32, shuffle=True)# Tomar una imagen del generador de entrenamientoimagen, etiqueta = next(data_gen_entrenamiento)'''# Imprimir y visualizar algunas imágenes del generador de entrenamientofor i in range(5): # Cambia el número 5 por el número de imágenes que deseas visualizar imagen, etiqueta = next(data_gen_entrenamiento) print("Etiqueta:", etiqueta) print("Dimensiones de la imagen:", imagen.shape) # Verificar las dimensiones print("Valor máximo de píxel:", np.max(imagen)) print("Valor mínimo de píxel:", np.min(imagen)) # Visualizar la imagen plt.imshow(imagen[0]) # Muestra solo la primera imagen del lote plt.title("Imagen " + str(i+1)) # Título con el número de imagen plt.show()'''#Congelar el modelo descargadourl = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4"mobilenetv2 = hub.KerasLayer(url, input_shape=(224,224,3))mobilenetv2.trainable = Falsemodelo = tf.keras.Sequential([ mobilenetv2, tf.keras.layers.Dense(11, activation='softmax')])modelo.summary()#Compilar como siempremodelo.compile( optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'] )#Entrenar el modeloEPOCAS = 50historial = modelo.fit( data_gen_entrenamiento, epochs=EPOCAS, batch_size=32, validation_data=data_gen_pruebas)
IT IS A MODEL FOR IMAGES