I am reading 230 images as arrays from 2 different folders and resizing it such that it would keep the aspect ratio intact of each image(Resized image size width=600 * height=800). After that I am trying to separate the labels and image arrays into 2 different list. Now before giving the image array list to CNN model I am reshaping it to reshape([-1, 3, 600, 800]) format, but I am getting error as:
ValueError: cannot reshape array of size 230 into shape (3,600,800)
How can I reshape it in above format?
Code written is:
def create_data():
for category in LABELS:
path = os.path.join(DATADIR,category)
class_num = LABELS.index(category) # get the classification (0 or a 1).
for img in tqdm(os.listdir(path)):
img_array = cv2.imread(os.path.join(path,img)) # convert to array
fac = np.array(img_array).shape[0]/np.array(img_array).shape[1]
new_array = cv2.resize(img_array, (600, int(np.ceil((fac*600)))))# resize to normalize data size
data.append([new_array, class_num]) # add to data
create_data()
Xtest = []
ytest = []
for features,label in data:
Xtest.append(features)
ytest.append(label)
X = np.array(Xtest).reshape([-1, 3, 600, 800])
deep-learning
orconv-neural-network
- kindly do not spam irrelevant tags (removed & replaced withopencv
&cv2
) – desertnaut