############################################################################### # Load the data from disk ############################################################################### tstart = time() db = YouTubeFacesDB('ytfdb.h5', mean_removal=True, output_type='vector') N = db.nb_samples d = db.input_dim C = db.nb_classes print(N, 'images of size', d, 'loaded in', time()-tstart) ############################################################################### # Split into a training set and a test set ############################################################################### db.split_dataset(validation_size=0.25) X_train, y_train = db.get('train') X_test, y_test = db.get('val') ############################################################################### # Train a not very deep network ############################################################################### print('Create the network...') model = Sequential() # Convolutional input layer with maxpooling and dropout model.add(Convolution2D(16, 6, 6, border_mode='valid', input_shape=d)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.5))
# Load the data from disk ############################################################################### tstart = time() db = YouTubeFacesDB('ytfdb.h5', mean_removal=True, output_type='vector') N = db.nb_samples d = db.input_dim C = db.nb_classes mean_face = db.mean print(N, 'images of size', d, 'loaded in', time() - tstart) ############################################################################### # Split into a training set and a test set ############################################################################### db.split_dataset(validation_size=0.25) ############################################################################### # Train a not very deep network ############################################################################### print('Create the network...') model = Sequential() # Convolutional input layer with maxpooling and dropout model.add(Convolution2D(16, 6, 6, border_mode='valid', input_shape=d)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.5)) # Fully connected with ReLU and dropout model.add(Flatten())
import torch.cuda import torch import torch.nn as nn import torch.optim as optim from torch.autograd import Variable from pathlib2 import Path import os # Read the script directory, will come in handy later! script_dir = os.path.dirname(__file__) # Read the database file # db = YouTubeFacesDB('/home/ritvik/dl4cv/ytfdb.h5') db = YouTubeFacesDB(os.path.join(script_dir, "ytfdb.h5")) # db = YouTubeFacesDB('/home/ritvik/testdata.h5') db.split_dataset(validation_size=0.2, test_size=0.1) testAcc = [] testLogs = open("testRecognizerLogs.txt", "a") # Check if a previously saved model exists myNetwork = Path("recognizer.pt") if myNetwork.is_file(): print("Saved model exists...!!!") network = torch.load("recognizer.pt") if torch.cuda.is_available(): network.cuda() ######################################### ############TEST THE MODEL############### ######################################### for inputs_test, labels_test in db.generate_batches(batch_size=100,