In [1]:
import os
import subprocess
In [2]:
import datetime
time_start = datetime.datetime.now()
print time_start
2015-02-06 22:30:00.415193

In [3]:
BASEDIR = "/home/efg/2015/Kaggle/Plankton/"

# DIRWALK = [dirpath, direnames, filenames]
DIRWALK = [fileNameDir for fileNameDir in os.walk(BASEDIR)]
In [4]:
print DIRWALK[2][0]
print DIRWALK[15][0]
/home/efg/2015/Kaggle/Plankton/train/appendicularian_slight_curve
/home/efg/2015/Kaggle/Plankton/train/unknown_unclassified

In [5]:
for i in [2,15]:
    print i, DIRWALK[i][0], len(DIRWALK[i][2])
    for j in range(len(DIRWALK[i][2])):        
        filename = DIRWALK[i][2][j]
        if j > 0 and j % 2500 == 0:
            print j, filename
        basename = os.path.join(DIRWALK[i][0], filename.rsplit(".",2)[0])
        # print j, filename
        subprocess.check_output(["convert", basename+".jpg", basename+".tif"])
        # Use print for debug
        # print subprocess.check_output(["convert", basename+".jpg", basename+".tif"])
        os.remove(basename+".jpg")
2 /home/efg/2015/Kaggle/Plankton/train/appendicularian_slight_curve 532
15 /home/efg/2015/Kaggle/Plankton/train/unknown_unclassified 425

In [6]:
time_stop = datetime.datetime.now()
print time_stop
print (time_stop - time_start), "overall convert time"
2015-02-06 22:30:11.345387
0:00:10.930194 overall convert time