Я о написании кода для классификации изображений. С ImageDataGenerator я написал свой код, но он работал очень медленно (1 с = 1 шаг). Я хочу загрузить свои собственные данные в виде массива np, но у меня появилось несколько ошибок.
Вывод должен быть: (15500, 45, 45,3) (4000, 1) (15500, 45, 45,3 ) (4000,1)
Но я получил:
(15500, 45, 45,3) (4000,) (15500, 45, 45,3) (4000,)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
import keras
import glob
import cv2
import os
TEST_DATADIR = "C:/Users/TCSEAKIN/Desktop/Py/AI-hack/AI/Test"
TRAIN_DATADIR = "C:/Users/TCSEAKIN/Desktop/Py/AI-hack/AI/Training"
CATAGORIES = ["Armut", "Portakal", "Cilek", "Muz", "Portakal", "Elma_Kirmizi", "Elma_Yesil", "Mandalina"]
fruit_images = []
labels = []
for category in CATAGORIES :
path = os.path.join(TRAIN_DATADIR, category)
for img in os.listdir(path):
image = cv2.imread(os.path.join(path,img), cv2.IMREAD_COLOR)
image = cv2.resize(image, (45, 45))
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
fruit_images.append(image)
labels.append(path)
fruit_images = np.array(fruit_images)
labels = np.array(labels)
validation_fruit_images = []
validation_labels = []
for category in CATAGORIES:
path = os.path.join(TEST_DATADIR, category)
for img in os.listdir(path):
image = cv2.imread(os.path.join(path,img), cv2.IMREAD_COLOR)
image = cv2.resize(image, (45, 45))
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
validation_fruit_images.append(image)
validation_labels.append(path)
validation_fruit_images = np.array(validation_fruit_images)
validation_labels = np.array(validation_labels)
X_train, X_test = fruit_images, validation_fruit_images
Y_train, Y_test = labels, validation_labels
#Normalize color values to between 0 and 1
X_train = X_train/255
X_test = X_test/255
print(X_train.shape)
print(Y_train.shape)
print(X_test.shape)
print(Y_test.shape)