Demo entry 6631466

the first version of solution to SRTP's puzzle 1

   

Submitted by zyplanet on Jul 15, 2017 at 11:57
Language: Python. Code size: 2.6 kB.

from scipy import misc
import glob
import numpy as np
from sklearn import metrics
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
flag=0
#load the vehicle images of far view
for image_path in glob.glob("/home/zyplanet/Documents/srtp/OwnCollection/vehicles/Far/*.png"):
	image=np.array([misc.imread(image_path,flatten=1)])
	if flag==0:
		image_ar_train=image
		flag=1
		continue
	image_ar_train=np.vstack((image_ar_train,image))

for image_path in glob.glob("/home/zyplanet/Documents/srtp/OwnCollection/vehicles/MiddleClose/*.png"):
	image=np.array([misc.imread(image_path,flatten=1)])
	image_ar_train=np.vstack((image_ar_train,image))

for image_path in glob.glob("/home/zyplanet/Documents/srtp/OwnCollection/vehicles/Left/*.png"):
	image=np.array([misc.imread(image_path,flatten=1)])
	image_ar_train=np.vstack((image_ar_train,image))

for image_path in glob.glob("/home/zyplanet/Documents/srtp/OwnCollection/vehicles/Right/*.png"):
	image=np.array([misc.imread(image_path,flatten=1)])
	image_ar_train=np.vstack((image_ar_train,image))

for image_path in glob.glob("/home/zyplanet/Documents/srtp/OwnCollection/non-vehicles/Far/*.png"):
	image=np.array([misc.imread(image_path,flatten=1)])
	image_ar_train=np.vstack((image_ar_train,image))

for image_path in glob.glob("/home/zyplanet/Documents/srtp/OwnCollection/non-vehicles/MiddleClose/*.png"):
	image=np.array([misc.imread(image_path,flatten=1)])
	image_ar_train=np.vstack((image_ar_train,image))

for image_path in glob.glob("/home/zyplanet/Documents/srtp/OwnCollection/non-vehicles/Right/*.png"):
	image=np.array([misc.imread(image_path,flatten=1)])
	image_ar_train=np.vstack((image_ar_train,image))

for image_path in glob.glob("/home/zyplanet/Documents/srtp/OwnCollection/non-vehicles/Left/*.png"):
	image=np.array([misc.imread(image_path,flatten=1)])
	image_ar_train=np.vstack((image_ar_train,image))

targetlab=np.ones(3425,int)
targetlab=np.append(targetlab,np.zeros(3900,int))

n_samples = len(image_ar_train)
data = image_ar_train.reshape((n_samples, -1))

X_train, X_test, Y_train, Y_test = train_test_split(data,targetlab,test_size=0.35,random_state=0)
print(X_train.shape,Y_train.shape)
layers=30*np.ones(12,int)
classifier = MLPClassifier(hidden_layer_sizes=layers,solver='adam',alpha=1e-5,random_state=1,early_stopping=True)
classifier.fit(X_train,Y_train)
expected=Y_test
predicted=classifier.predict(X_test)
print("Classification report for classifier %s:\n%s\n"% (classifier, metrics.classification_report(expected, predicted)))

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).