ssvm = learners.NSlackSSVM( model, verbose=2, C=1, max_iter=1000, n_jobs=-1, tol=0.0001, show_loss_every=5, inactive_threshold=1e-3, inactive_window=10, batch_size=100) ssvm.fit(X_valid, valid_Y) print ssvm.score(X_valid,valid_Y) print ssvm.score(X_test,test_Y) predict = ssvm.predict(X_valid) for i in range(0, len(X_valid)): predict_result = predict[i] fe = Feature() x = glob.glob("../data_road/training/image/um_000001.png") print len(x) fe.loadImage(x[0]) fe.loadSuperpixelImage() image = fe.getImage() superpixels = valid_superpixels[i][0] newIm = np.zeros((image.shape[0], image.shape[1], image.shape[2])) numSuperpixels = np.max(superpixels)+1 for i in xrange(0,numSuperpixels): indices = np.where(superpixels==i) prediction = predict_result[i] image[indices] = 1 sp.showPlots("im_name", image, numSuperpixels, superpixels) #superpixels = #sp.showPlots(x, y_pred[0], np.max(superpixels),superpixels): #print y_pred # we throw away void superpixels and flatten everything
valid_pixels_labels = [] test_pixels_labels = [] valid_files = [] test_files = [] valid_files_count = 0 test_files_count = 0 valid_superpixels = [] validationOriginalImage = [] test_superpixels = [] testOriginalImage = [] train_superpixels = [] for i in xrange(0,num_files): fe = Feature() fe.loadImage(im_file_names[i]) fe.loadSuperpixelImage() #fe.loadSuperpixelFromFile(sp_file_names[i]) fe.loadLabelImage(label_file_names[i]) featureVectors = fe.getFeaturesVectors() labels = fe.getSuperPixelLabels() #Test purposes edges, edgeFeatures1, edgeFeatures2 = fe.getEdges() if file_labels[i] != TESTING_LABEL: # store data if file_labels[i] == TRAINING_LABEL: train_edges.append(edges) train_edgesFeatures1.append(edgeFeatures1)
valid_edgesFeatures2 = [] valid_pixels_labels = [] test_pixels_labels = [] valid_files = [] test_files = [] valid_files_count = 0 test_files_count = 0 valid_superpixels = [] validationOriginalImage = [] test_superpixels = [] testOriginalImage = [] train_superpixels = [] for i in xrange(0, num_files): fe = Feature() fe.loadImage(im_file_names[i]) fe.loadSuperpixelImage() #fe.loadSuperpixelFromFile(sp_file_names[i]) fe.loadLabelImage(label_file_names[i]) featureVectors = fe.getFeaturesVectors() labels = fe.getSuperPixelLabels() #Test purposes edges, edgeFeatures1, edgeFeatures2 = fe.getEdges() if file_labels[i] != TESTING_LABEL: # store data if file_labels[i] == TRAINING_LABEL: train_edges.append(edges) train_edgesFeatures1.append(edgeFeatures1)
tol=0.0001, show_loss_every=5, inactive_threshold=1e-3, inactive_window=10, batch_size=100) ssvm.fit(X_valid, valid_Y) print ssvm.score(X_valid, valid_Y) print ssvm.score(X_test, test_Y) predict = ssvm.predict(X_valid) for i in range(0, len(X_valid)): predict_result = predict[i] fe = Feature() x = glob.glob("../data_road/training/image/um_000001.png") print len(x) fe.loadImage(x[0]) fe.loadSuperpixelImage() image = fe.getImage() superpixels = valid_superpixels[i][0] newIm = np.zeros((image.shape[0], image.shape[1], image.shape[2])) numSuperpixels = np.max(superpixels) + 1 for i in xrange(0, numSuperpixels): indices = np.where(superpixels == i) prediction = predict_result[i] image[indices] = 1 sp.showPlots("im_name", image, numSuperpixels, superpixels) #superpixels = #sp.showPlots(x, y_pred[0], np.max(superpixels),superpixels): #print y_pred # we throw away void superpixels and flatten everything