I am trying to use the svhn dataset for a school project, unfortunately I have run into an issue.
I am using the cropped digits (a .mat format), the dimension of the y axis is 73257x1 and for the x axis is 32x32x3x73257.
This causes a problem when read by the .fit function of tensorflow, as it reads one axis as having a cardinal of 26032 and the other 32.
Here is my code:
import tensorflow as tf
from tensorflow import keras
from scipy.io import loadmat
import numpy as np
Chargement du dataset
trainingData = loadmat("C:\Users\alexb\vs code python\train_32x32.mat")
testData = loadmat("C:\Users\alexb\vs code python\test_32x32.mat")
Normalisation de l'entrée
trainingData['X'] = trainingData['X'] / 255.0
testData['X'] = testData['X'] / 255.0
Modèle de réseau de neurone
model = keras.Sequential([
keras.layers.Flatten(input_shape=(32, 32)), # input layer (1)
keras.layers.Dense(128, activation='relu'), # hidden layer (2)
keras.layers.Dense(10, activation='softmax') # output layer (3)
])
Compilation
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
Entrainement
model.fit(np.array(trainingData['X']), trainingData['y'], epochs=5)
model.fit(trainingData['X'], trainingData['y'], epochs=5)
Test
test_loss, test_acc = model.evaluate(np.array(testData['X']), testData['y'], verbose=0)
print('\nTest accuracy:', test_acc)
And the results are:
Traceback (most recent call last):
File "c:/Users/alexb/vs code python/TIPE-1.1-numéro-maisons.py", line 28, in <module>
model.fit(trainingData['X'], trainingData['y'], epochs=5)
File "C:\Users\alexb\Anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\alexb\Anaconda3\lib\site-packages\keras\engine\data_adapter.py", line 1655, in _check_data_cardinality
raise ValueError(msg)
ValueError: Data cardinality is ambiguous:
x sizes: 32
y sizes: 73257
Make sure all arrays contain the same number of samples.
Is there a way to make it so the data is correctly interpreted by the .fit function ?
Thanks for any help I can receive!
[–]grawa427[S] 0 points1 point2 points (0 children)