'CNN model accuracy fluctuates

Tensorflow/Keras

I have developed a CNN model to classify images as circle, triangle or square. However, my accuracy values have wide fluctuations. Is it something to do with my data preprocessing?

This is my code for data preprocessing:

Edit: I am using this folder Folder structure Edit2: I am using this model Model

input_folder = r"C:\Users\User\OneDrive\Documents\Trimester_2 2022 (6 Subjects)\AI\Assignment\three_shapes"
output_folder = r"C:\Users\User\OneDrive\Documents\Trimester_2 2022 (6 Subjects)\AI\Assignment\splited_data"
splitfolders.ratio(input_folder, output_folder, seed = 42, ratio = (.7, .2, .1),)


os.chdir(r"C:\Users\User\OneDrive\Documents\Trimester_2 2022 (6 Subjects)\AI\Assignment\splited_data")

os.makedirs("train/circle")
os.makedirs("train/square")
os.makedirs("train/triangle")
os.makedirs("val/circle")
os.makedirs("val/square")
os.makedirs("val/triangle")
os.makedirs("test/circle")
os.makedirs("test/square")
os.makedirs("test/triangle")

list = ["train/", "test/", "val/"]
for i in list:
    for name in glob.glob(i + "triangle*"):
        shutil.move(name, i + "triangle")
    for name in glob.glob(i + "circle*"):
        shutil.move(name, i + "circle")
    for name in glob.glob(i + "square*"):
        shutil.move(name, i + "square")



IMAGE_WIDTH = 200
IMAGE_HEIGHT = 200

train_gen = ImageDataGenerator(rescale = 1/255).flow_from_directory(
    directory=r"train", # the path to the 'shapes' directory.
    target_size=(IMAGE_WIDTH, IMAGE_HEIGHT),
    classes=["circle", "square", "triangle"],
    batch_size=200,
    class_mode="categorical",
)

test_gen = ImageDataGenerator(rescale = 1/255).flow_from_directory(
    directory=r"test", # the path to the 'shapes' directory.
    target_size=(IMAGE_WIDTH, IMAGE_HEIGHT),
    classes=["circle", "square", "triangle"],
    batch_size=200,
    class_mode="categorical",
)

val_gen = ImageDataGenerator(rescale = 1/255).flow_from_directory(
    directory=r"val", # the path to the 'shapes' directory.
    target_size=(IMAGE_WIDTH, IMAGE_HEIGHT),
    classes=["circle", "square", "triangle"],
    batch_size=200,
    class_mode="categorical",
)


Solution 1:[1]

It is easy, I am trying to generate those inputs but my work also indicates shapes-sensitive categories such as Galaxy games. Your models do not need anything special excepts matching on target responsive and layers. ( You see when training of the good response from model training )

[ Sample ]:

identity_cell = tf.image.flip_up_down( cropped_image ).numpy()
identity_cell = identity_cell + cropped_image.numpy()

identity_cell = tf.where( tf.greater_equal( identity_cell, np.ones((n_yaxis, n_xais, channel)) * 0.300 ), [1], [0], name=None ).numpy()
identity_cell = tf.math.count_nonzero(identity_cell)

... Sample

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martijn Pieters