Guys I am trying to create a application to create training data import os
import cv2
import matplotlib.pyplot as plt
from colorama import Fore
import random
import numpy as np
import pickle

training_data = []
def create_training_data():
path = os.getcwd()
path_dataset = os.path.join(path,'dataset')
categories = ['a','b']
for category in categories:
    path_categories = os.path.join(path_dataset,category)
    index = categories.index(category)
    for img in os.listdir(path_categories):
        try:
            path = os.path.join(path_categories,img)
            img_array = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
            training_data.append([img_array,index])
        except Exception as e:
            print(Fore.RED+path)
    print(Fore.GREEN+f"imported all data from cateogry {category}")



#For every object in the training dataset
#training_data[element][data type*]
#0 - Stores the values of all images
#1 -  stores the values of all category

create_training_data()

print(training_data[1201][1])
plt.imshow(training_data[1201][0],cmap="gray")
rows,columns = training_data[0][0].shape
print(f"rows-{rows} cols-{columns}")
plt.show()
random.shuffle(training_data)
X = []
Y = []

for feature,label in training_data:
X.append(feature)
Y.append(label)

X = np.array(X).reshape(-1,rows,columns,1)


pickle_out = open(X.pickle,'wb')
pickle.dump(X,pickle_out)
pickle_out.close()

pickle_out = open(Y.pickle,'wb')
pickle.dump(Y,pickle_out)
pickle_out.close()


After I run this script I am getting an error:

Traceback (most recent call last):
  File "trainingdata.py", line 55, in 
    pickle_out = open(X.pickle,'wb')
AttributeError: 'numpy.ndarray' object has no attribute 'pickle'
The error in the line pickle_out = open(X.pickle,'wb') is that the name of file must be in quotes. So the correct code would be:

pickle_out = open('X.pickle','wb')
pickle.dump(X,pickle_out)
pickle_out.close()


Do the same for Y also. Also you can do it more concisely in the following way:

with open('X.pickle', 'wb') as f:
    pickle.dump(X, f)