[Python] Training CNN model for image classifier

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am stuck hereby as I am making an model which can classify art into three class whether it is painting , digital art , sculpture.

    I have a data set with 2k images each now I am stuck how to build a good model

    Can anyone tell me what is going wrong or what I am doing wrong .

    I checked metrices like precision and recall, they are upwards of 90% but accuracy lags behind (24% only).

    What could be the potential reasons?

    • my data is clean
    • I have two directories (training and validation)
    • both have further subdirectories (corresponding to digitalart, painting, and sculpture with an equal number of samples)

    model = keras.Sequential([ # we are using the sequential api here it GOOD FOR simple model
    layers.Conv2D(32, (3, 3), activation='relu', input_shape=(256, 256, 3)), # this is first convolutional layer has 32 filters , using relu to introduce non-linearity
    # we define all these things in first layer later on all layers automatically inherit these props
    layers.MaxPooling2D(), # this reduces the dimension like image hieght and width
    layers.Conv2D(64, (3, 3), activation='relu'), # second layer
    layers.MaxPooling2D(),
    layers.Conv2D(128, (3, 3), activation='relu'), # third
    layers.MaxPooling2D(),
    layers.Flatten(), # converts 2d feature maps into one 1d to male fully connected layers

    layers.Dense(128, activation='relu'), # fully connected layer
    layers.Dense(3, activation='softmax') # 3 classes: painting, sculpture, digital art three neuron as three output
    ])

    # Compile model
    model.compile(optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy'])

    Continue reading...

Compartilhe esta Página