Click here to Skip to main content
15,916,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list of images with shape (150 x 150 x 3) the list of images contains 100 images and array of labels, a label for each image with total count 100 label.
And I have the label of each image in an array
Now I want to fit my data in that model I tried model.fit(x,y) but it didn't work it gave me this error
```
ValueError: Data cardinality is ambiguous:
  x sizes: 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 113, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 110, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150
  y sizes: 100
Make sure all arrays contain the same number of samples.

```

What I have tried:

this is how i read and store my images
Trainimages=[]
    Testimages = []
    imagepaths=list(paths.list_images("C:/Users/Geforce/Downloads/Compressed/ci-sc22-places-and-scene-recognition/train_images"))
    imagepathstest=list(paths.list_images("C:/Users/Geforce/Downloads/Compressed/ci-sc22-places-and-scene-recognition/test_images"))
    print(imagepaths[0])
    img=cv2.imread(imagepaths[0])
    
    for i in range(100):
        im = cv2.imread(imagepaths[i])
        Trainimages.append(im)
      x=Trainimages

this is how i set the labels from the .csv file
df = pd.read_csv('train2.csv')
    print(df["image_name"])
    n = copy.deepcopy(df["label"])
    print("---------------------")
    imgname = df["image_name"]
    for i in range(len(imgname)):
        # print(imgname.iloc[i])
        x = imgname.iloc[i].split(".")
        n[i] = int(x[0])

    df["X"] = n
    print(df)
    df = df.sort_values(by="X")
    df = df.drop("X", 1)
    print("--------------------------------------")
    print(df)

    
   
    print(type(g))
    y= df["labels"].to_numpy()

this is my model
def myModel():
    input=Input((1,150,150,3))
    out=Conv2D(filters=96,kernel_size=(11,11),strides=(1,1),name="conv1")(input)
    out=Activation('relu')(out)
    out = Conv2D(filters=256, kernel_size=(5, 5), strides=(1, 1), name="conv2")(out)
    out = Activation('relu')(out)
    out = Conv2D(filters=384, kernel_size=(3, 3), strides=(1, 1), name="conv3")(out)
    out = Activation('relu')(out)
    out = Conv2D(filters=384, kernel_size=(3, 3), strides=(1, 1), name="conv4")(out)
    out = Activation('relu')(out)
    out = Conv2D(filters=256, kernel_size=(3, 3), strides=(1, 1), name="conv5")(out)
    out = Activation('relu')(out)
    out=  Dense(units=4096,activation='relu',name="FC1")(out)
    out = Dense(units=4096, activation='relu', name="FC2")(out)
    out = Dense(units=6, activation='softmax', name="classes")(out)
    model=keras.models.Model(inputs=input,outputs=out)
    model.compile(loss="sparse_categorical_crossentropy",optimizer=Adam(lr=0.01))
    return model

this is how i fit my data
```
model.fit(x,y)
```
Posted
Comments
Richard MacCutchan 21-Dec-21 6:05am    
The error message, and its suggested solution are clear: Make sure all arrays contain the same number of samples..
Bahy Mohamed 21-Dec-21 6:09am    
they have the same number of samples
x is a list that has 100 images
y is an array that has 100 labels a label foreach image
Richard MacCutchan 21-Dec-21 6:14am    
Well that is not what the error message states.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900