Last active
May 30, 2016 08:44
-
-
Save Mambix/56cdab86b283a18cf45c0079e86eb3a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
# Generate labels.txt and train.txt files for caffee trainig dataset | |
import os | |
import sys | |
targetDir = sys.argv[1] | |
root, dirs, files = os.walk(targetDir).next() | |
print('Root: %s' % root) | |
print('DIRs: %s' % dirs) | |
print('Files: %s' % files) | |
dirs.sort() | |
files = [] | |
labels = {} | |
with open('%s/_labels.txt' % root, 'w') as L: | |
with open('%s/_train.txt' % root, 'w') as T: | |
for dir in dirs: | |
L.write("%s\n" % dir) | |
for R, D, F in os.walk('%s/%s' % (root, dir)): | |
for f in F: | |
T.write("%s/%s %s\n" % (R, f, dir)) | |
print('Done!!!') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
# Cut out images to create trainig set | |
import sys | |
from PIL import Image | |
size = 16 | |
fileName = sys.argv[1] | |
if len(sys.argv) > 2: | |
size = int(sys.argv[2]) | |
im = Image.open('%s.png' % fileName) | |
w = 0 | |
h = 0 | |
while h + size < im.size[1]: | |
w = 0 | |
while w + size < im.size[0]: | |
im.crop((w, h, w+size, h+size)).save('%s-%s-%s.png' % (fileName, h, w)) | |
w += 1 | |
h += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment