Kim404
Kim404

Reputation: 67

I faced an empty training_Data

So I tried this tutorial (minutes 11:58) trying to implement on my CNN which consist of 10 species on the dataset.

i got no error to load data

DATADIR = "dataset"
CATEGORIES = ["Dendrobium_crumenatum","Grammatophyllum_speciosum", "Coelogyne_swaniana", 
              "Bulbophyllum_purpurascens", "Agrostophyllum_stipulatum", 
              "Spathoglottis_plicata", "Phalaenopsis_amabilis", "Nabaluia_angustifolia", 
              "Habenaria_rhodocheila_hance"]

 here the example of the output
[![enter image description here][2]][2]

then the next section is

training_data = []
def create_training_data():
    for category in CATEGORIES:
        path = os.path.join(DATADIR,category)
        class_num = CATEGORIES.index(category)
        for img in os.listdir(path):
            try:
                img_array = cv2.imread(os.path.join(path,img),cv2.IMREAD_GRAYSCALE)
                new_array = cv2.resize(img_array, (IMG_SIZE,IMG_SIZE))
                training_data.append([new,array, class_num])
            except Exception as e:
                pass
create_training_data()        

but when I print prin(len(training_data))

i got this as output

0

and when i tried

import random
random.shuffle(training_data)
for sample in training_data[:10]:
    print (sample[1])

it shows no output. is that means, my training data is empty? or because of the index of categories being used? because I'm using 10 class while in tutorial used 2 class.

Upvotes: 0

Views: 95

Answers (1)

Mohammad Sartaj
Mohammad Sartaj

Reputation: 111

make your training_data global

training_data =[]
def create_training_data():
    global training_data
    for category in CATEGORIES:
        path = os.path.join(DATADIR,category)
        class_num = CATEGORIES.index(category)
        for img in os.listdir(path):
            try:
                img_array = cv2.imread(os.path.join(path,img),cv2.IMREAD_GRAYSCALE)
                new_array = cv2.resize(img_array,(IMG_SIZE, IMG_SIZE))
                training_data.append([new_array,class_num])
            except Exception as e:
                pass
create_training_data()

Upvotes: 1

Related Questions