コード例 #1
0
            2, 1,
            0))  # the reference model has channels in BGR order instead of RGB
        if net_name == "AlexNet":
            self.net.blobs['data'].reshape(1, 3, 227, 227)
        else:
            self.net.blobs['data'].reshape(1, 3, 224, 224)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("net", help="Net, Choose from: AlexNet, VGG, VGG_SOS")
    parser.add_argument("figure_name", help="Please specify MAIN file name")
    parser.add_argument("PATH_TO_DATA",
                        help="Please specify the path to the images")
    parser.add_argument("annotations", help="Annotated frames")
    parser.add_argument("--PATH_TO_DATA_2",
                        help="Please specify the path to second set of images",
                        default=None)
    parser.add_argument("--annotations_2",
                        help="Annotated frames for second set of images",
                        default=None)
    args = parser.parse_args()
    fe = CNNFeatureExtractor(args.net)
    layers = constants.NET_PARAMS[args.net][2]

    X = fe.forward_pass(args.PATH_TO_DATA,
                        args.annotations,
                        list_of_layers=layers,
                        sampling_rate=1)
    utils.plot_all_layers(X, args.net, args.figure_name, list_of_layers=layers)
コード例 #2
0
		hypercolumns_layers = ['conv2','conv3', 'conv4']
		X, label_map, frm_map = fe.forward_pass(args.PATH_TO_DATA, args.annotations, hypercolumns_layers)
		X_hc = utils.make_hypercolumns_vector(hypercolumns_layers, X)
		utils.plot_hypercolumns(X_hc, args.net, label_map, frm_map, args.figure_name, hypercolumns_layers)
	elif args.vlad:
		layers = ['conv4', 'conv3']
		k_values = [1, 5, 10]
		pc_values = [5, 100, 200]
		X, label_map, frm_map = fe.forward_pass(args.PATH_TO_DATA, args.annotations, list_of_layers = layers, sampling_rate = 1)
		utils.vlad_experiment(X, k_values, pc_values, label_map, frm_map, args.figure_name, list_of_layers = layers)

	elif args.batch_size != -1 and not args.LCD:
		layers = ['conv3', 'conv4', 'conv5', 'pool5']
		X, label_map, frm_map = fe.forward_pass(args.PATH_TO_DATA, args.annotations,list_of_layers = layers, sampling_rate = 1, batch_size = int(args.batch_size))
		utils.plot_all_layers(X, args.net, label_map, frm_map, args.figure_name, list_of_layers = layers)

	elif args.LCD:
		if args.batch_size == -1:
			print "ERROR: Please provide both batch size and LCD"
			sys.exit()
		layers = ['conv5_1', 'conv5_2', 'conv5_3' ]
		X, label_map, frm_map = fe.forward_pass(args.PATH_TO_DATA, args.annotations, list_of_layers = layers, sampling_rate = 1, batch_size = int(args.batch_size), LCD = True)
		utils.plot_all_layers(X, args.net, label_map, frm_map, args.figure_name, list_of_layers = layers)

	else:
		print "Plotting Individual frames"
		X, label_map, frm_map = fe.forward_pass(args.PATH_TO_DATA, args.annotations, list_of_layers = layers, sampling_rate = 3)
		data = [X, label_map, frm_map]
		pickle.dump(data, open(args.figure_name + ".p", "wb"))
		utils.plot_all_layers(X, args.net, label_map, frm_map, args.figure_name, list_of_layers = layers)
コード例 #3
0
	def init_caffe(self, net_name):
		caffe.set_mode_gpu()
		net_params = constants.NET_PARAMS[net_name]
		self.net = caffe.Net(net_params[0], net_params[1], caffe.TEST)
		self.transformer = caffe.io.Transformer({'data': self.net.blobs['data'].data.shape})
		self.transformer.set_transpose('data', (2,0,1))
		# self.transformer.set_mean('data', np.load(constants.CAFFE_ROOT + 'python/caffe/imagenet/ilsvrc_2012_mean.npy').mean(1).mean(1)) # mean pixel
		self.transformer.set_raw_scale('data', 255)  # the reference model operates on images in [0,255] range instead of [0,1]
		self.transformer.set_channel_swap('data', (2,1,0))  # the reference model has channels in BGR order instead of RGB
		if net_name == "AlexNet":
			self.net.blobs['data'].reshape(1,3,227,227)
		else:
			self.net.blobs['data'].reshape(1,3,224,224)


if __name__ == "__main__":
	parser = argparse.ArgumentParser()
	parser.add_argument("net", help = "Net, Choose from: AlexNet, VGG, VGG_SOS")
	parser.add_argument("figure_name", help = "Please specify MAIN file name")
	parser.add_argument("PATH_TO_DATA", help="Please specify the path to the images")
	parser.add_argument("annotations", help = "Annotated frames")
	parser.add_argument("--PATH_TO_DATA_2", help="Please specify the path to second set of images", default = None)
	parser.add_argument("--annotations_2", help = "Annotated frames for second set of images", default = None)
	args = parser.parse_args()
	fe = CNNFeatureExtractor(args.net)
	layers = constants.NET_PARAMS[args.net][2]

	X = fe.forward_pass(args.PATH_TO_DATA, args.annotations, list_of_layers = layers, sampling_rate = 1)
	utils.plot_all_layers(X, args.net, args.figure_name, list_of_layers = layers)