Skip to content

Commit 9a713a0

Browse files
committed
ENH Process data in canonical (sorted) order
This avoid introducing small variations on the results just based on filesystem ordering.
1 parent 0c9a32e commit 9a713a0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ch10/simple_classification.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
print('Computing features...')
2424
# Use glob to get all the images
2525
images = glob('{}/*.jpg'.format(basedir))
26-
for fname in images:
26+
27+
# We sort the images to ensure that they are always processed in the same order
28+
# Otherwise, this would introduce some variation just based on the random
29+
# ordering that the filesystem uses
30+
for fname in sorted(images):
2731
im = mh.imread(fname, as_grey=True)
2832
haralicks.append(texture(im))
2933
sobels.append(edginess_sobel(im))

ch12/image-classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def print_results(scores_base, scores_combined):
7272

7373
# Use glob to get all the images
7474
images = glob('{}/*.jpg'.format(basedir))
75-
for fname in images:
75+
for fname in sorted(images):
7676
haralicks.append(features_for(fname))
7777
sobels.append(edginess_sobel_from_fname(fname))
7878
labels.append(fname[:-len('00.jpg')]) # The class is encoded in the filename as xxxx00.jpg

0 commit comments

Comments
 (0)