Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import os
- import cv2
- from tqdm import tqdm
- DATADIR = "E:\Kash project files\Manveer\DataCollection\Scattered\Testing"
- CATEGORIES = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
- IMG_SIZE = 100
- training_data = []
- def create_training_data():
- for category in CATEGORIES:
- path = os.path.join(DATADIR,category)
- class_num = CATEGORIES.index(category)
- for img in tqdm(os.listdir(path)):
- try:
- img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE) # convert to array
- new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) # resize to normalize data size
- training_data.append([new_array, class_num]) # add this to our training_data
- except Exception as e: # in the interest in keeping the output clean...
- pass
- #except OSError as e:
- # print("OSErrroBad img most likely", e, os.path.join(path,img))
- #except Exception as e:
- # print("general exception", e, os.path.join(path,img))
- create_training_data()
- print(len(training_data))
- import random
- random.shuffle(training_data)
- for sample in training_data[:10]:
- print(sample[1])
- X = []
- y = []
- for features,label in training_data:
- X.append(features)
- y.append(label)
- print(X[0].reshape(-1, IMG_SIZE, IMG_SIZE, 1))
- X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
- import h5py
- # import pickle
- # pickle_out = open("x_test_plastic40.pickle","wb")
- # pickle.dump(X, pickle_out)
- # pickle_out.close()
- # pickle_out = open("y_test_plastic40.pickle","wb")
- # pickle.dump(y, pickle_out)
- # pickle_out.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement