0

I am about writing a code for Image Classification. With ImageDataGenerator i wrote my code but it was working very slow ( 1s = 1 step ) . I want to load my own data as a np array but i got some errors.

The output should be: (15500 , 45 ,45,3) (4000, 1) (15500 , 45 ,45,3) (4000,1)

But i got :

(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)
2
  • 1
    The test shapes are not 'wrong'. In the case of a one-dimensional array, it is a tuple with one element instead of an integer value. A tuple with one element has a trailing comma. Commented May 3, 2020 at 22:20
  • labels=labels.reshape(4000,1) Commented May 4, 2020 at 5:43

1 Answer 1

3

use the reshape function:

labels = labels.reshape(-1, 1)
labels.shape
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.