Skip to content

Commit cc3bb49

Browse files
committed
Python3 friendly printing in examples
1 parent e3aee32 commit cc3bb49

6 files changed

Lines changed: 28 additions & 28 deletions

File tree

python_examples/face_detector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
win = dlib.image_window()
3636

3737
for f in sys.argv[1:]:
38-
print "processing file: ", f
38+
print("processing file: ", f)
3939
img = io.imread(f)
4040
# The 1 in the second argument indicates that we should upsample the image
4141
# 1 time. This will make everything bigger and allow us to detect more
4242
# faces.
4343
dets = detector(img,1)
44-
print "number of faces detected: ", len(dets)
44+
print("number of faces detected: ", len(dets))
4545
for d in dets:
46-
print " detection position left,top,right,bottom:", d.left(), d.top(), d.right(), d.bottom()
46+
print(" detection position left,top,right,bottom:", d.left(), d.top(), d.right(), d.bottom())
4747

4848
win.clear_overlay()
4949
win.set_image(img)

python_examples/max_cost_assignment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
# This prints optimal assignments: [2, 0, 1]
4141
# which indicates that we should assign the person from the first row of the cost matrix to
4242
# job 2, the middle row person to job 0, and the bottom row person to job 1.
43-
print "optimal assignments: ", assignment
43+
print("optimal assignments: ", assignment)
4444

4545

4646
# This prints optimal cost: 16.0
4747
# which is correct since our optimal assignment is 6+5+5.
48-
print "optimal cost: ", dlib.assignment_cost(cost, assignment)
48+
print("optimal cost: ", dlib.assignment_cost(cost, assignment))
4949

5050

python_examples/sequence_segmenter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def print_segment(sentence, names):
176176
# We can also measure the accuracy of a model relative to some labeled data. This
177177
# statement prints the precision, recall, and F1-score of the model relative to the data in
178178
# training_sequences/segments.
179-
print "Test on training data:", dlib.test_sequence_segmenter(model, training_sequences, segments)
179+
print("Test on training data:", dlib.test_sequence_segmenter(model, training_sequences, segments))
180180

181181
# We can also do 5-fold cross-validation and print the resulting precision, recall, and F1-score.
182-
print "cross validation:", dlib.cross_validate_sequence_segmenter(training_sequences, segments, 5, params)
182+
print("cross validation:", dlib.cross_validate_sequence_segmenter(training_sequences, segments, 5, params))
183183

184184

python_examples/svm_rank.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
# Now if you call rank on a vector it will output a ranking score. In
5454
# particular, the ranking score for relevant vectors should be larger than the
5555
# score for non-relevant vectors.
56-
print "ranking score for a relevant vector: ", rank(data.relevant[0])
57-
print "ranking score for a non-relevant vector: ", rank(data.nonrelevant[0])
56+
print("ranking score for a relevant vector: ", rank(data.relevant[0]))
57+
print("ranking score for a non-relevant vector: ", rank(data.nonrelevant[0]))
5858
# The output is the following:
5959
# ranking score for a relevant vector: 0.5
6060
# ranking score for a non-relevant vector: -0.5
@@ -65,12 +65,12 @@
6565
# In this case, the ordering accuracy tells us how often a non-relevant vector
6666
# was ranked ahead of a relevant vector. In this case, it returns 1 for both
6767
# metrics, indicating that the rank function outputs a perfect ranking.
68-
print dlib.test_ranking_function(rank, data)
68+
print(dlib.test_ranking_function(rank, data))
6969

7070
# The ranking scores are computed by taking the dot product between a learned
7171
# weight vector and a data vector. If you want to see the learned weight vector
7272
# you can display it like so:
73-
print "weights: \n", rank.weights
73+
print("weights: \n", rank.weights)
7474
# In this case the weights are:
7575
# 0.5
7676
# -0.5
@@ -112,7 +112,7 @@
112112
# splits and returns the overall ranking accuracy based on the held out data.
113113
# Just like test_ranking_function(), it reports both the ordering accuracy and
114114
# mean average precision.
115-
print "cross validation results: ", dlib.cross_validate_ranking_trainer(trainer, queries, 4)
115+
print("cross validation results: ", dlib.cross_validate_ranking_trainer(trainer, queries, 4))
116116

117117

118118

@@ -141,8 +141,8 @@
141141

142142
trainer = dlib.svm_rank_trainer_sparse()
143143
rank = trainer.train(data)
144-
print "ranking score for a relevant vector: ", rank(data.relevant[0])
145-
print "ranking score for a non-relevant vector: ", rank(data.nonrelevant[0])
144+
print("ranking score for a relevant vector: ", rank(data.relevant[0]))
145+
print("ranking score for a non-relevant vector: ", rank(data.nonrelevant[0]))
146146
# Just as before, the output is the following:
147147
# ranking score for a relevant vector: 0.5
148148
# ranking score for a non-relevant vector: -0.5

python_examples/svm_struct.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def main():
4646

4747
# Print the weights and then evaluate predict_label() on each of our training samples.
4848
# Note that the correct label is predicted for each sample.
49-
print weights
49+
print(weights)
5050
for i in range(len(samples)):
51-
print "predicted label for sample[{0}]: {1}".format(i, predict_label(weights, samples[i]))
51+
print("predicted label for sample[{0}]: {1}".format(i, predict_label(weights, samples[i])))
5252

5353
def predict_label(weights, sample):
5454
"""Given the 9-dimensional weight vector which defines a 3 class classifier, predict the

python_examples/train_object_detector.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
# the path to this faces folder as a command line argument so we will know
2525
# where it is.
2626
if (len(sys.argv) != 2):
27-
print "Give the path to the examples/faces directory as the argument to this"
28-
print "program. For example, if you are in the python_examples folder then "
29-
print "execute this program by running:"
30-
print " ./train_object_detector.py ../examples/faces"
27+
print("Give the path to the examples/faces directory as the argument to this")
28+
print("program. For example, if you are in the python_examples folder then ")
29+
print("execute this program by running:")
30+
print(" ./train_object_detector.py ../examples/faces")
3131
exit()
3232
faces_folder = sys.argv[1]
3333

@@ -59,18 +59,18 @@
5959
# images with boxes. To see how to use it read the tools/imglab/README.txt
6060
# file. But for this example, we just use the training.xml file included with
6161
# dlib.
62-
dlib.train_simple_object_detector(faces_folder+"/training.xml","detector.svm", options)
62+
dlib.train_simple_object_detector(faces_folder+"/training.xml", "detector.svm", options)
6363

6464

6565

6666
# Now that we have a face detector we can test it. The first statement tests
67-
# it on the training data. It will print the precision, recall, and then
67+
# it on the training data. It will print(the precision, recall, and then)
6868
# average precision.
69-
print "\ntraining accuracy:", dlib.test_simple_object_detector(faces_folder+"/training.xml", "detector.svm")
69+
print("\ntraining accuracy:", dlib.test_simple_object_detector(faces_folder+"/training.xml", "detector.svm"))
7070
# However, to get an idea if it really worked without overfitting we need to
7171
# run it on images it wasn't trained on. The next line does this. Happily, we
7272
# see that the object detector works perfectly on the testing images.
73-
print "testing accuracy: ", dlib.test_simple_object_detector(faces_folder+"/testing.xml", "detector.svm")
73+
print("testing accuracy: ", dlib.test_simple_object_detector(faces_folder+"/testing.xml", "detector.svm"))
7474

7575

7676

@@ -84,15 +84,15 @@
8484

8585
# Now let's run the detector over the images in the faces folder and display the
8686
# results.
87-
print "\nShowing detections on the images in the faces folder..."
87+
print("\nShowing detections on the images in the faces folder...")
8888
win = dlib.image_window()
8989
for f in glob.glob(faces_folder+"/*.jpg"):
90-
print "processing file:", f
90+
print("processing file:", f)
9191
img = io.imread(f)
9292
dets = detector(img)
93-
print "number of faces detected:", len(dets)
93+
print("number of faces detected:", len(dets))
9494
for d in dets:
95-
print " detection position left,top,right,bottom:", d.left(), d.top(), d.right(), d.bottom()
95+
print(" detection position left,top,right,bottom:", d.left(), d.top(), d.right(), d.bottom())
9696

9797
win.clear_overlay()
9898
win.set_image(img)

0 commit comments

Comments
 (0)