def read(self, img_rows=IMAGE_SIZE, img_cols=IMAGE_SIZE, img_channels=3, nb_classes=2): images, labels = extract_data(self.TRAIN_DATA) labels = np.reshape(labels, [-1]) X_train, X_test, y_train, y_test = train_test_split( images, labels, test_size=0.3, random_state=random.randint(0, 100)) X_valid, X_test, y_valid, y_test = train_test_split( images, labels, test_size=0.5, random_state=random.randint(0, 100)) if K.image_dim_ordering() == 'th': X_train = X_train.reshape(X_train.shape[0], img_channels, img_rows, img_cols) X_valid = X_valid.reshape(X_valid.shape[0], img_channels, img_rows, img_cols) X_test = X_test.reshape(X_test.shape[0], img_channels, img_rows, img_cols) input_shape = (img_channels, img_rows, img_cols) else: X_train = X_train.reshape(X_train.shape[0], img_rows, img_cols, img_channels) X_valid = X_valid.reshape(X_valid.shape[0], img_rows, img_cols, img_channels) X_test = X_test.reshape(X_test.shape[0], img_rows, img_cols, img_channels) input_shape = (img_rows, img_cols, img_channels) print('X_train shape:', X_train.shape) print(X_train.shape[0], 'train samples') print(X_valid.shape[0], 'valid samples') print(X_test.shape[0], 'test samples') Y_train = np_utils.to_categorical(y_train, nb_classes) Y_valid = np_utils.to_categorical(y_valid, nb_classes) Y_test = np_utils.to_categorical(y_test, nb_classes) X_train = X_train.astype('float32') X_valid = X_valid.astype('float32') X_test = X_test.astype('float32') X_train /= 255 X_valid /= 255 X_test /= 255 self.X_train = X_train self.X_valid = X_valid self.X_test = X_test self.Y_train = Y_train self.Y_valid = Y_valid self.Y_test = Y_test
def read(self): image,label=extract_data() label=label.reshape((label.shape[0],)) n=[i for i in range(image.shape[0])] random.shuffle(n) image=image[n] label=label[n] X_train=image[0:384] Y_train=label[0:384] X_valid=image[384:512] Y_valid=label[384:512] X_test=image[512:] Y_test=label[512:] img_rows,img_cols=64,64 nb_classes=2 if K.image_dim_ordering() == 'th': X_train = X_train.reshape(X_train.shape[0], 3, img_rows, img_cols) X_valid = X_valid.reshape(X_valid.shape[0], 3, img_rows, img_cols) X_test = X_test.reshape(X_test.shape[0], 3, img_rows, img_cols) input_shape = (3, img_rows, img_cols) else: X_train = X_train.reshape(X_train.shape[0], img_rows, img_cols, 3) X_valid = X_valid.reshape(X_valid.shape[0], img_rows, img_cols, 3) X_test = X_test.reshape(X_test.shape[0], img_rows, img_cols, 3) input_shape = (img_rows, img_cols, 3) # the data, shuffled and split between train and test sets print('X_train shape:', X_train.shape) print(X_train.shape[0], 'train samples') print(X_valid.shape[0], 'valid samples') print(X_test.shape[0], 'test samples') # convert class vectors to binary class matrices Y_train = np_utils.to_categorical(Y_train, nb_classes) Y_valid = np_utils.to_categorical(Y_valid, nb_classes) Y_test = np_utils.to_categorical(Y_test, nb_classes) X_train = X_train.astype('float32') X_valid = X_valid.astype('float32') X_test = X_test.astype('float32') X_train /= 255 X_valid /= 255 X_test /= 255 self.X_train = X_train self.X_valid = X_valid self.X_test = X_test self.Y_train = Y_train self.Y_valid = Y_valid self.Y_test = Y_test
def read(self, img_rows=IMAGE_SIZE, img_cols=IMAGE_SIZE, img_channels=3, nb_classes=2): images, labels = extract_data('./data/' + ip + '/') labels = np.reshape(labels, [-1]) # numpy.reshape X_train, X_test, y_train, y_test = train_test_split( images, labels, test_size=0.3, random_state=random.randint(0, 100)) X_valid, X_test, y_valid, y_test = train_test_split( images, labels, test_size=0.5, random_state=random.randint(0, 100)) if K.image_dim_ordering() == 'th': X_train = X_train.reshape(X_train.shape[0], 3, img_rows, img_cols) X_valid = X_valid.reshape(X_valid.shape[0], 3, img_rows, img_cols) X_test = X_test.reshape(X_test.shape[0], 3, img_rows, img_cols) input_shape = (3, img_rows, img_cols) else: X_train = X_train.reshape(X_train.shape[0], img_rows, img_cols, 3) X_valid = X_valid.reshape(X_valid.shape[0], img_rows, img_cols, 3) X_test = X_test.reshape(X_test.shape[0], img_rows, img_cols, 3) input_shape = (img_rows, img_cols, 3) # the data, shuffled and split between train and test sets print('X_train shape:', X_train.shape) print(X_train.shape[0], 'train samples') print(X_valid.shape[0], 'valid samples') print(X_test.shape[0], 'test samples') # convert class vectors to binary class matrices Y_train = np_utils.to_categorical(y_train, nb_classes) Y_valid = np_utils.to_categorical(y_valid, nb_classes) Y_test = np_utils.to_categorical(y_test, nb_classes) X_train = X_train.astype('float32') X_valid = X_valid.astype('float32') X_test = X_test.astype('float32') X_train /= 255 X_valid /= 255 X_test /= 255 self.X_train = X_train self.X_valid = X_valid self.X_test = X_test self.Y_train = Y_train self.Y_valid = Y_valid self.Y_test = Y_test
def read(self, img_rows=IMAGE_SIZE_HEIGHT, img_cols=IMAGE_SIZE_WIDTH, img_channels=3, nb_classes=2): images, labels = extract_data('./data1/') # labels = np.reshape(labels, [-1]) # numpy.reshape X_train, X_test, y_train, y_test = train_test_split( images, labels, test_size=0.3, stratify=labels, random_state=random.randint(0, 100)) X_valid, _, y_valid, _ = train_test_split(images, labels, test_size=0.5, random_state=random.randint( 0, 100)) # the data, shuffled and split between train and test sets print 'X_train shape:', X_train.shape print X_train.shape[0], 'train samples' print X_valid.shape[0], 'valid samples' print X_test.shape[0], 'test samples' # convert class vectors to binary class matrices Y_train = np_utils.to_categorical(y_train, nb_classes) Y_valid = np_utils.to_categorical(y_valid, nb_classes) Y_test = np_utils.to_categorical(y_test, nb_classes) X_train = X_train.astype('float32') X_valid = X_valid.astype('float32') X_test = X_test.astype('float32') X_train /= 255 X_valid /= 255 X_test /= 255 self.X_train = X_train self.X_valid = X_valid self.X_test = X_test self.Y_train = Y_train self.Y_valid = Y_valid self.Y_test = Y_test
def read(self, input_dir): images, labels, nb_classes = extract_data(input_dir) # shuffle and split data between train and test sets x_train, x_test, y_train, y_test = train_test_split( images, labels, test_size=0.3, random_state=random.randint(0, 100) ) x_valid, x_test, y_valid, y_test = train_test_split( images, labels, test_size=0.5, random_state=random.randint(0, 100) ) print('x_train shape:', x_train.shape) print(x_train.shape[0], 'train samples') print(x_valid.shape[0], 'valid samples') print(x_test.shape[0], 'test samples') # # convert class vectors to binary class matrices # y_train = np_utils.to_categorical(y_train, nb_classes) # y_valid = np_utils.to_categorical(y_valid, nb_classes) # y_test = np_utils.to_categorical(y_test, nb_classes) x_train = x_train.astype('float32') x_valid = x_valid.astype('float32') x_test = x_test.astype('float32') x_train /= 255 x_valid /= 255 x_test /= 255 self.x_train = x_train self.x_valid = x_valid self.x_test = x_test self.y_train = y_train self.y_valid = y_valid self.y_test = y_test return nb_classes
else: y = 0 h += 2 * CropPadding if x > CropPadding: x = x - CropPadding else: x = 0 w += 2 * CropPadding return [x, y, w, h] if __name__ == '__main__': model = Model() model.load() # Get Cascade Classifier cascade = cv2.CascadeClassifier(cascade_path) images, labels = extract_data(test_path) labels = np.reshape(labels, [-1]) right = 0 cross = 0 countme = 0 countnotme = 0 rightme = 0 rightnotme = 0 for idx, image in enumerate(images): # To gray image if GRAY_MODE == True: #frame_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) frame_gray = image else: