Hi @Kiran_Sai_Ramineni, I used your code for example:
import os
import numpy as np
from PIL import Image
import tensorflow as tf
from tqdm import tqdm
from sklearn.model_selection import train_test_split
image_list =
labels =
def load_images_as_numpy(directory, max_images=None):
filenames = os.listdir(directory)[:max_images] if max_images else os.listdir(directory)
for filename in tqdm(filenames, desc=“Загрузка файлов”):
x = filename.strip(‘.png’)
labels.append(x)
if filename.endswith(“.png”):
image_path = os.path.join(directory, filename)
image = Image.open(image_path)
image_array = np.array(image)
image_list.append(image_array)
return np.array(image_list)
images_directory = input("Введите путь к директории с изображениями: ")
total_images = len(os.listdir(images_directory))
print(f"Общее количество доступных изображений: {total_images}")
max_images = int(input("Введите максимальное количество изображений для загрузки (или оставьте пустым): ") or total_images)
epochs = int(input("Введите количество эпох: "))
print(“Загрузка изображений…”)
images_numpy_array = load_images_as_numpy(images_directory, max_images)
print(“Изображения успешно загружены.”)
Normalize pixel values to the range [0, 1]
images_numpy_array = images_numpy_array.astype(‘float32’) / 255.0
label_to_int = {label: index for index, label in enumerate(labels)}
int_labels = [label_to_int[label] for label in labels]
one_hot_labels = tf.keras.utils.to_categorical(int_labels, num_classes=max_images)
Split data into training and validation sets
x_train, x_val, y_train, y_val = train_test_split(images_numpy_array, one_hot_labels, test_size=0.2, random_state=42)
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Conv2D(32, (3, 3), activation=‘relu’, input_shape=(50, 130, 3)))
model.add(tf.keras.layers.MaxPooling2D((2, 2)))
model.add(tf.keras.layers.Conv2D(64, (3, 3), activation=‘relu’))
model.add(tf.keras.layers.MaxPooling2D((2, 2)))
model.add(tf.keras.layers.Conv2D(128, (3, 3), activation=‘relu’))
model.add(tf.keras.layers.MaxPooling2D((2, 2)))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(128, activation=‘relu’))
model.add(tf.keras.layers.Dense(max_images, activation=‘softmax’))
model.compile(optimizer=‘adam’, loss=‘categorical_crossentropy’, metrics=[‘accuracy’])
model.fit(x_train, y_train, epochs=epochs, batch_size=32)
but as you can see the result is 0, I sent 10000 pictures for training, if you send 100 everything works in the first 3 epochs
Logs:
Epoch 118/200
250/250 [==============================] - 27s 108ms/step - loss: 8.9944 - accur
acy: 0.0000e+00
Epoch 119/200
250/250 [==============================] - 27s 110ms/step - loss: 8.9944 - accur
acy: 1.2500e-04
Epoch 120/200
250/250 [==============================] - 28s 114ms/step - loss: 8.9944 - accur
acy: 0.0000e+00
Epoch 121/200
250/250 [==============================] - 26s 106ms/step - loss: 8.9944 - accur
acy: 0.0000e+00
Epoch 122/200
250/250 [==============================] - 29s 115ms/step - loss: 8.9944 - accur
acy: 0.0000e+00
Epoch 123/200
250/250 [==============================] - 27s 106ms/step - loss: 8.9944 - accur
acy: 0.0000e+00
Epoch 124/200
139/250 [===============>…] - ETA: 11s - loss: 8.9909 - accuracy: 0
.0000e+00