Beispiel #1
0
def get_dataset(size, partition, label_category=None, skip=1):
	"""
	:param size: 0:mini, 1:small, 2:medium, 3:large
	:param label_category: 0:moving, 1:position, 2:in/outdoor
	"""
	train_x, train_y = load_data.load_prepared_data(load_data.load_sample_expId(size, partition), skip=skip)
	if label_category is not None:
		train_y = numpy.asarray(train_y[:,label_category], dtype='int32')
	else:
		train_y = numpy.asarray(train_y, dtype='int32')
	return [train_x, train_y]
Beispiel #2
0
def repr_feature_default(layer=4, tsne=False):
	convnet = cPickle.load(open('../models/moving_alg_conv.pkl'))
	sharedset = shared_dataset(load_data(load_sample_expId(0, 'vc'), sliding_step=500), convnet.static_sensor)
	return repr_feature(convnet, sharedset, layer, tsne)
Beispiel #3
0
		
	repr_x_all = []
	for layer in [1,2,4,-1]:
		repr_x, repr_y = repr_feature(convnet, sharedset, layer=layer)
		rf_model_name = "moving_rf_layer%i_%s" % (layer,model_name)
		start_time = timeit.default_timer()
		print "start building %s" % rf_model_name
		model = build_rf([repr_x, repr_y[:,0]], "../models/%s.pkl" % rf_model_name)
		end_time = timeit.default_timer()
		print "%f sec elapsed to build random forest for layer%i" % (end_time-start_time, layer)
	
		#repr_x_all.append(repr_x)
	#repr_x_all = numpy.asarray(repr_x_all)
	#model = build_rf([repr_x_all, repr_y[:,0]], "../models/moving_rf_all_layer_%s" % (model_name))	
	"""
	validset = shared_dataset(load_data(load_sample_expId(0, 'vc'), sliding_step=50), convnet.static_sensor)
	for layer in [1,2,4,-1]:
		print "start extracting features of layer%i" % layer
		repr_x, repr_y = repr_feature(convnet, validset, layer=layer)

		rf_model_name = "moving_rf_layer%i_%s" % (layer,model_name)
		model = cPickle.load(open("../models/%s.pkl" % rf_model_name))
		print "model %s loaded" % rf_model_name

		pred_y = model.predict(repr_x)
		real_y = repr_y[:,0]

		import sklearn.metrics
		print 1-sklearn.metrics.accuracy_score(real_y, pred_y)
		print sklearn.metrics.classification_report(real_y, pred_y)
		print sklearn.metrics.confusion_matrix(real_y, pred_y)