def run_ensemble(train_filename, train_path, test_filename, test_path, result_filename, output_filename, coords_filename, batch_size, step_size): network = VGRAM(params['output']['width'], params['output']['height']) network.connections = [ ConnectionRandom(input_layer=ConnectionInput(params['input']['width'], params['input']['height'], 0), synapses=params['connection_rand']['synapses']), ConnectionGaussian(input_layer=ConnectionInput( params['input']['width'], params['input']['height'], 1), synapses=params['connection_gaus']['synapses'], radius=params['connection_gaus']['radius']) ] train_data, train_label, _, _ = LoadDataset(train_filename, train_path) network.train(train_data, train_label) test_data, test_label, x, y = LoadDataset(test_filename, test_path) test_data, test_label = ClearFalseNegatives(train_label, test_label, test_data) print 'Train size:', train_label.shape[0] print 'Test size:', test_label.shape[0] test_size = test_label.shape[0] pred_label = -1 * np.ones((test_size, ), dtype=int) pred_buffer = -1 * np.ones((batch_size, batch_size), dtype=int) for i in xrange(test_size): test_data_i = test_data[i:i + batch_size, :] predicted = network.testSequence(test_data_i, step_list(step_size)) ''' pred_label[i] = predicted[0] ''' pred_buffer = np.roll(pred_buffer, -1, axis=0) pred_buffer[batch_size - 1, :] = np.pad( predicted, (0, batch_size - predicted.shape[0]), 'constant', constant_values=-1) pred_label[i] = MajorityVoteWithinSecondaryDiagonal(pred_buffer) print pred_label[i], test_label[i], predicted pred_label[0:batch_size] = test_label[0: batch_size] #disregard first results result_file = open(result_filename, 'w') for frame_radius in xrange(19): result = EvaluateOutput(pred_label, test_label.flatten(), max_number_of_frames=frame_radius) print >> result_file, (result * 100.0) np.savetxt(output_filename, [pred_label, test_label]) np.savetxt(coords_filename, [x, y])
def run_ensemble(train_filename, train_path, test_filename, test_path, result_filename, output_filename, coords_filename, batch_size, step_size): network = VGRAM(params['output']['width'], params['output']['height']) network.connections = [ ConnectionRandom(input_layer=ConnectionInput(params['input']['width'], params['input']['height'], 0), synapses=params['connection_rand']['synapses']), ConnectionGaussian(input_layer=ConnectionInput(params['input']['width'], params['input']['height'], 1), synapses=params['connection_gaus']['synapses'], radius=params['connection_gaus']['radius']) ] train_data, train_label, _, _ = LoadDataset(train_filename, train_path) network.train(train_data, train_label) test_data, test_label, x, y = LoadDataset(test_filename, test_path) test_data, test_label = ClearFalseNegatives(train_label, test_label, test_data) print 'Train size:', train_label.shape[0] print 'Test size:', test_label.shape[0] test_size = test_label.shape[0] pred_label = -1 * np.ones((test_size,), dtype=int) pred_buffer = -1 * np.ones((batch_size, batch_size), dtype=int) for i in xrange(test_size): test_data_i = test_data[i:i+batch_size,:] predicted = network.testSequence(test_data_i, step_list(step_size)) ''' pred_label[i] = predicted[0] ''' pred_buffer = np.roll(pred_buffer, -1, axis=0) pred_buffer[batch_size-1,:] = np.pad(predicted, (0,batch_size-predicted.shape[0]), 'constant', constant_values=-1) pred_label[i] = MajorityVoteWithinSecondaryDiagonal(pred_buffer) print pred_label[i], test_label[i], predicted pred_label[0:batch_size] = test_label[0:batch_size] #disregard first results result_file = open(result_filename, 'w') for frame_radius in xrange(19): result = EvaluateOutput(pred_label, test_label.flatten(), max_number_of_frames=frame_radius) print>>result_file, (result * 100.0) np.savetxt(output_filename, [pred_label, test_label]) np.savetxt(coords_filename, [x, y])
def run_vgram(train_filename, train_path, test_filename, test_path, result_filename, output_filename, coords_filename, batch_size): network = VGRAM(params['output']['width'], params['output']['height']) network.connections = [ ConnectionRandom(input_layer=ConnectionInput(params['input']['width'], params['input']['height'], 0), synapses=params['connection_rand']['synapses']), ConnectionGaussian(input_layer=ConnectionInput( params['input']['width'], params['input']['height'], 1), synapses=params['connection_gaus']['synapses'], radius=params['connection_gaus']['radius']) ] memory_size, input_size, num_samples = LoadDataset(train_filename) print 'Train size:', memory_size, input_size, num_samples, train_filename network.train(memory_size, input_size, num_samples, train_filename, True) memory_size, input_size, num_samples = LoadDataset(test_filename) print 'Test size:', memory_size, input_size, num_samples, test_filename output_data, test_label = network.test(memory_size, input_size, num_samples, test_filename, True) '''the output computed below takes the closest of top 3 most voted, which is closest to the previous''' #pred_label = NetworkOutput.MajorityVoteClosestToPrevious(output_data, test_label.shape[0]) #pred_label = NetworkOutput.MajorityVoteClosestToPrevious2(output_data, test_label.shape[0], test_label[0]) '''the output computed below takes the closest of top 3 most voted, which is closest to ground truth''' #pred_label = NetworkOutput.MajorityVoteClosestToExpected(output_data, test_label) '''the output computed below takes the most voted and doesn't take into consideration the confidence''' pred_label, confidence = NetworkOutput.MajorityVoteAndConfidence( output_data, num_samples) #ClearLowConfidence(pred_label, confidence, 0.1) #pred_label[0:batch_size] = test_label[0:batch_size] #disregard first results result_file = open(result_filename, 'w') for frame_radius in xrange(19): result = EvaluateOutput(pred_label, test_label.flatten(), max_number_of_frames=frame_radius) print(result * 100.0) print >> result_file, (result * 100.0)
def run_vgram(train_filename, train_path, test_filename, test_path, result_filename, output_filename, coords_filename, batch_size): network = VGRAM(params['output']['width'], params['output']['height']) network.connections = [ ConnectionRandom(input_layer=ConnectionInput(params['input']['width'], params['input']['height'], 0), synapses=params['connection_rand']['synapses']), ConnectionGaussian(input_layer=ConnectionInput(params['input']['width'], params['input']['height'], 1), synapses=params['connection_gaus']['synapses'], radius=params['connection_gaus']['radius']) ] train_data, train_label, _, _ = LoadDataset(train_filename, train_path) network.train(train_data, train_label) #network.unload() #network.reload() test_data, test_label, x, y = LoadDataset(test_filename, test_path) test_data, test_label = ClearFalseNegatives(train_label, test_label, test_data) print 'Train size:', train_label.shape[0] print 'Test size:', test_label.shape[0] output_data = network.test(test_data, test_label) '''the output computed below takes the closest of top 3 most voted, which is closest to the previous''' #pred_label = NetworkOutput.MajorityVoteClosestToPrevious(output_data, test_label.shape[0]) #pred_label = NetworkOutput.MajorityVoteClosestToPrevious2(output_data, test_label.shape[0], test_label[0]) '''the output computed below takes the closest of top 3 most voted, which is closest to ground truth''' #pred_label = NetworkOutput.MajorityVoteClosestToExpected(output_data, test_label) '''the output computed below takes the most voted and doesn't take into consideration the confidence''' pred_label, confidence = NetworkOutput.MajorityVoteAndConfidence(output_data, test_label.shape[0]) #ClearLowConfidence(pred_label, confidence, 0.1) pred_label[0:batch_size] = test_label[0:batch_size] #disregard first results result_file = open(result_filename, 'w') for frame_radius in xrange(19): result = EvaluateOutput(pred_label, test_label.flatten(), max_number_of_frames=frame_radius) print>>result_file, (result * 100.0) np.savetxt(output_filename, [pred_label, test_label]) np.savetxt(coords_filename, [x, y])
image_clahe[:,:,0] = ImageProcProxy.applyCLAHE(image_roi[:,:,0]) image_clahe[:,:,1] = ImageProcProxy.applyCLAHE(image_roi[:,:,1]) image_clahe[:,:,2] = ImageProcProxy.applyCLAHE(image_roi[:,:,2]) image_resized = ImageProcProxy.resizeInterLinear(image_clahe, params['input']['width'], params['input']['height']) image_gaussian = ImageProcProxy.applyGaussian(image_resized, params['filter']['gaussian_radius'], params['filter']['gaussian_sigma']) image_int = ImageProcProxy.convertBGR2INT(image_gaussian) image_vector = ImageProcProxy.flattenImage(image_int) input_images[sample]= image_vector return input_images, file_list['classId'] if __name__ == '__main__': network = VGRAM(params['output']['width'], params['output']['height']) network.connections = [ConnectionLogPolar(input_layer=ConnectionInput(params['input']['width'], params['input']['height']), synapses=params['connection']['synapses'], radius=params['connection']['radius'], factor=params['connection']['factor'])] input_data, class_data = LoadDataset(params['dataset']['train']['file'], params['dataset']['train']['path']) network.train(input_data, class_data) input_data, class_data = LoadDataset(params['dataset']['test']['file'], params['dataset']['train']['path']) output_data = network.test(input_data, class_data) output_value= NetworkOutput.MajorityVoteMean(output_data, class_data.flatten()) * 100.0 print "Percentage correct =", output_value, "%"
image_resized, params['filter']['gaussian_radius'], params['filter']['gaussian_sigma']) image_int = ImageProcProxy.convertBGR2INT(image_gaussian) image_vector = ImageProcProxy.flattenImage(image_int) input_images[sample] = image_vector return input_images, file_list['classId'] if __name__ == '__main__': network = VGRAM(params['output']['width'], params['output']['height']) network.connections = [ ConnectionLogPolar(input_layer=ConnectionInput( params['input']['width'], params['input']['height']), synapses=params['connection']['synapses'], radius=params['connection']['radius'], factor=params['connection']['factor']) ] input_data, class_data = LoadDataset(params['dataset']['train']['file'], params['dataset']['train']['path']) network.train(input_data, class_data) input_data, class_data = LoadDataset(params['dataset']['test']['file'], params['dataset']['train']['path']) output_data = network.test(input_data, class_data) output_value = NetworkOutput.MajorityVoteMean(output_data, class_data.flatten()) * 100.0 print "Percentage correct =", output_value, "%"
params['input']['height']) image_gaussian = ImageProcProxy.applyGaussian( image_resized, params['filter']['gaussian_radius'], params['filter']['gaussian_sigma']) image_vector = ImageProcProxy.flattenImage(image_gaussian) input_images[sample] = image_vector return input_images[:finalsize], labels[:finalsize] if __name__ == '__main__': network = VGRAM(params['output']['width'], params['output']['height']) network.connections = [ ConnectionGaussian(input_layer=ConnectionInput( params['input']['width'], params['input']['height']), synapses=params['connection']['synapses'], radius=params['connection']['radius']) ] input_data, class_data = LoadDataset(params['dataset']['train']['images'], params['dataset']['train']['labels'], params['dataset']['train']['total']) network.train(input_data, class_data) input_data, class_data = LoadDataset(params['dataset']['test']['images'], params['dataset']['test']['labels'], params['dataset']['test']['total']) output_data = network.test(input_data, class_data) print "Percentage correct =", NetworkOutput.MajorityVoteMean( output_data, class_data.flatten()) * 100.0, "%"
from pyram.mae.vgram.vgram_core import VGRAM from pyram.mae.vgram.vgram_output import NetworkOutput from pyram.mae.vgram.vgram_synapse import ConnectionGaussian, ConnectionRandom, ConnectionInput from example_placerecog_utils import LoadDataset, ProcessImage, ClearFalseNegatives, EvaluateOutput from example_placerecog_utils import LoadDatasetAndCropImages from example_placerecog_config import params import numpy as np if __name__ == '__main__': network = VGRAM(params['output']['width'], params['output']['height']) network.connections = [ ConnectionRandom(input_layer=ConnectionInput(params['input']['width'], params['input']['height'], 0), synapses=params['connection_rand']['synapses']), ConnectionGaussian(input_layer=ConnectionInput(params['input']['width'], params['input']['height'], 1), synapses=params['connection_gaus']['synapses'], radius=params['connection_gaus']['radius']) ] train_data, train_label, _, _ = LoadDataset(params['dataset']['train']['file'], params['dataset']['train']['path']) network.train(train_data, train_label) #network.unload() #network.reload() test_data, test_label = LoadDatasetAndCropImages(params['dataset']['test']['file'], params['dataset']['test']['path']) test_data, test_label = ClearFalseNegatives(train_label, test_label, test_data) confidence = np.zeros(test_label.shape[0], dtype=float) predicted = np.zeros(test_label.shape[0], dtype=int) for i in xrange(test_label.shape[0]):