Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5162e20

Browse files
committed
new design, rebuild docs
1 parent 47711b7 commit 5162e20

File tree

163 files changed

+26814
-8290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+26814
-8290
lines changed

_downloads/image_segmentation.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
===========================================
3+
Semantic Image Segmentation on Pascal VOC
4+
===========================================
5+
This example demonstrates learning a superpixel CRF
6+
for semantic image segmentation.
7+
To run the experiment, please download the pre-processed data from:
8+
http://www.ais.uni-bonn.de/~amueller/data/
9+
10+
The data consists of superpixels, unary potentials, and the connectivity
11+
structure of the superpixels.
12+
The unary potentials were originally provided by Philipp Kraehenbuehl:
13+
http://graphics.stanford.edu/projects/densecrf/
14+
15+
The superpixels were extracted using SLIC.
16+
The code for generating the connectivity graph and edge features will be made
17+
available soon.
18+
19+
This example does not contain the proper evaluation on pixel level, as that
20+
would need the Pascal VOC 2010 dataset.
21+
"""
22+
import numpy as np
23+
import cPickle
24+
25+
from pystruct import learners
26+
import pystruct.models as crfs
27+
from pystruct.utils import SaveLogger
28+
29+
30+
data_train = cPickle.load(open("data_train.pickle"))
31+
C = 0.01
32+
33+
n_states = 21
34+
print("number of samples: %s" % len(data_train.X))
35+
class_weights = 1. / np.bincount(np.hstack(data_train.Y))
36+
class_weights *= 21. / np.sum(class_weights)
37+
print(class_weights)
38+
39+
model = crfs.EdgeFeatureGraphCRF(inference_method='qpbo',
40+
class_weight=class_weights,
41+
symmetric_edge_features=[0, 1],
42+
antisymmetric_edge_features=[2])
43+
44+
experiment_name = "edge_features_one_slack_trainval_%f" % C
45+
46+
ssvm = learners.NSlackSSVM(
47+
model, verbose=2, C=C, max_iter=100000, n_jobs=-1,
48+
tol=0.0001, show_loss_every=5,
49+
logger=SaveLogger(experiment_name + ".pickle", save_every=100),
50+
inactive_threshold=1e-3, inactive_window=10, batch_size=100)
51+
ssvm.fit(data_train.X, data_train.Y)
52+
53+
data_val = cPickle.load(open("data_val.pickle"))
54+
y_pred = ssvm.predict(data_val.X)
55+
56+
# we throw away void superpixels and flatten everything
57+
y_pred, y_true = np.hstack(y_pred), np.hstack(data_val.Y)
58+
y_pred = y_pred[y_true != 255]
59+
y_true = y_true[y_true != 255]
60+
61+
print("Score on validation set: %f" % np.mean(y_true == y_pred))

_downloads/latent_node.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

_downloads/latent_svm.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

_downloads/latent_svm_as_crf.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

_downloads/multi_class_svm.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,33 @@
99
from time import time
1010
import numpy as np
1111

12-
#from sklearn.datasets import fetch_mldata
13-
from sklearn.datasets import load_digits
12+
from sklearn.datasets import fetch_mldata
13+
#from sklearn.datasets import load_digits
1414
from sklearn.cross_validation import train_test_split
15-
#from sklearn.svm import LinearSVC
15+
from sklearn.svm import LinearSVC
1616

17-
from pystruct.models import CrammerSingerSVMModel
17+
from pystruct.models import MultiClassClf
1818
from pystruct.learners import (NSlackSSVM, OneSlackSSVM,
1919
SubgradientSSVM)
2020

2121
# do a binary digit classification
22-
#digits = fetch_mldata("MNIST original")
23-
digits = load_digits()
22+
digits = fetch_mldata("USPS")
23+
#digits = load_digits()
2424
X, y = digits.data, digits.target
2525
#X = X / 255.
26-
X = X / 16.
27-
y = y.astype(np.int)
26+
#X = X / 16.
27+
y = y.astype(np.int) - 1
2828
X_train, X_test, y_train, y_test = train_test_split(X, y)
2929

30-
3130
# we add a constant 1 feature for the bias
3231
X_train_bias = np.hstack([X_train, np.ones((X_train.shape[0], 1))])
3332
X_test_bias = np.hstack([X_test, np.ones((X_test.shape[0], 1))])
3433

35-
pbl = CrammerSingerSVMModel(n_features=X_train_bias.shape[1], n_classes=10)
36-
n_slack_svm = NSlackSSVM(pbl, verbose=0, check_constraints=False, C=20,
37-
batch_size=-1, tol=1e-2)
38-
one_slack_svm = OneSlackSSVM(pbl, verbose=50, check_constraints=False, C=.20,
39-
max_iter=10000, tol=.001, show_loss_every=10)
40-
subgradient_svm = SubgradientSSVM(pbl, C=20, learning_rate=0.000001,
34+
model = MultiClassClf(n_features=X_train_bias.shape[1], n_classes=10)
35+
n_slack_svm = NSlackSSVM(model, verbose=2, check_constraints=False, C=0.1,
36+
batch_size=100, tol=1e-2)
37+
one_slack_svm = OneSlackSSVM(model, verbose=2, C=.10, tol=.001)
38+
subgradient_svm = SubgradientSSVM(model, C=0.1, learning_rate=0.000001,
4139
max_iter=1000, verbose=0)
4240

4341
# n-slack cutting plane ssvm
@@ -68,7 +66,7 @@
6866
# because of the way I construct psi, we use half the C
6967
# the standard one-vs-rest multi-class would probably be as good and faster
7068
# but solving a different model
71-
#libsvm = LinearSVC(multi_class='crammer_singer', C=10)
69+
#libsvm = LinearSVC(multi_class='crammer_singer', C=.1)
7270
#start = time()
7371
#libsvm.fit(X_train, y_train)
7472
#time_libsvm = time() - start

0 commit comments

Comments
 (0)