In [1]:
%reload_ext autoreload
%autoreload 2
%matplotlib inline
In [2]:
from fastai.vision import *
from fastai.metrics import error_rate
In [3]:
path = Path('Database')
In [4]:
path.ls()
Out[4]:
[PosixPath('Database/GoodPLR_0.404_7581.jpg'),
 PosixPath('Database/GoodPLR_0.433_2440.jpg'),
 PosixPath('Database/GoodPLR_0.352_5594.jpg'),
 PosixPath('Database/GoodPLR_0.46_5072.jpg'),
 PosixPath('Database/GoodPLR_0.37_914.jpg'),
 PosixPath('Database/GoodPLR_0.404_840.jpg'),
 PosixPath('Database/GoodPLR_0.404_9135.jpg'),
 PosixPath('Database/GoodPLR_0.509_6291.jpg'),
 PosixPath('Database/GoodPLR_0.389_3233.jpg'),
 PosixPath('Database/GoodPLR_0.46_1675.jpg'),
 PosixPath('Database/GoodPLR_0.391_4683.jpg'),
 PosixPath('Database/GoodPLR_0.439_7106.jpg'),
 PosixPath('Database/GoodPLR_0.442_3577.jpg'),
 PosixPath('Database/GoodPLR_0.259_2725.jpg'),
 PosixPath('Database/GoodPLR_0.463_3786.jpg'),
 PosixPath('Database/GoodPLR_0.52_3953.jpg'),
 PosixPath('Database/GoodPLR_0.434_7464.jpg'),
 PosixPath('Database/GoodPLR_0.349_8029.jpg'),
 PosixPath('Database/GoodPLR_0.421_4339.jpg'),
 PosixPath('Database/GoodPLR_0.339_9193.jpg'),
 PosixPath('Database/GoodPLR_0.404_3004.jpg'),
 PosixPath('Database/GoodPLR_0.36_8549.jpg'),
 PosixPath('Database/GoodPLR_0.362_2952.jpg'),
 PosixPath('Database/GoodPLR_0.37_478.jpg'),
 PosixPath('Database/GoodPLR_0.421_1363.jpg'),
 PosixPath('Database/GoodPLR_0.46_2342.jpg'),
 PosixPath('Database/GoodPLR_0.46_6261.jpg'),
 PosixPath('Database/GoodPLR_0.341_3736.jpg'),
 PosixPath('Database/GoodPLR_0.472_1775.jpg'),
 PosixPath('Database/GoodPLR_0.396_2996.jpg'),
 PosixPath('Database/GoodPLR_0.3_7677.jpg'),
 PosixPath('Database/GoodPLR_0.611_8898.jpg'),
 PosixPath('Database/GoodPLR_0.545_1715.jpg'),
 PosixPath('Database/GoodPLR_0.404_4433.jpg'),
 PosixPath('Database/GoodPLR_0.451_9843.jpg'),
 PosixPath('Database/GoodPLR_0.469_621.jpg'),
 PosixPath('Database/GoodPLR_0.457_649.jpg'),
 PosixPath('Database/GoodPLR_0.451_3790.jpg'),
 PosixPath('Database/GoodPLR_0.527_3408.jpg'),
 PosixPath('Database/GoodPLR_0.412_8090.jpg'),
 PosixPath('Database/GoodPLR_0.439_5332.jpg'),
 PosixPath('Database/GoodPLR_0.509_528.jpg'),
 PosixPath('Database/GoodPLR_0.453_97.jpg'),
 PosixPath('Database/GoodPLR_0.421_5869.jpg'),
 PosixPath('Database/GoodPLR_0.358_9200.jpg'),
 PosixPath('Database/GoodPLR_0.385_8919.jpg'),
 PosixPath('Database/GoodPLR_0.433_4170.jpg'),
 PosixPath('Database/GoodPLR_0.294_7891.jpg'),
 PosixPath('Database/GoodPLR_0.345_4944.jpg'),
 PosixPath('Database/GoodPLR_0.429_3374.jpg'),
 PosixPath('Database/GoodPLR_0.345_1363.jpg'),
 PosixPath('Database/GoodPLR_0.358_2210.jpg'),
 PosixPath('Database/GoodPLR_0.358_3472.jpg'),
 PosixPath('Database/GoodPLR_0.42_186.jpg'),
 PosixPath('Database/GoodPLR_0.35_9730.jpg'),
 PosixPath('Database/GoodPLR_0.345_2904.jpg'),
 PosixPath('Database/GoodPLR_0.396_866.jpg'),
 PosixPath('Database/GoodPLR_0.321_2785.jpg'),
 PosixPath('Database/GoodPLR_0.472_7271.jpg'),
 PosixPath('Database/GoodPLR_0.383_4186.jpg'),
 PosixPath('Database/GoodPLR_0.256_7193.jpg'),
 PosixPath('Database/GoodPLR_0.5_8621.jpg'),
 PosixPath('Database/GoodPLR_0.389_387.jpg'),
 PosixPath('Database/GoodPLR_0.468_8549.jpg'),
 PosixPath('Database/GoodPLR_0.393_4466.jpg'),
 PosixPath('Database/GoodPLR_0.446_2972.jpg'),
 PosixPath('Database/GoodPLR_0.56_5872.jpg'),
 PosixPath('Database/GoodPLR_0.48_5767.jpg'),
 PosixPath('Database/GoodPLR_0.4_3042.jpg'),
 PosixPath('Database/GoodPLR_0.434_2704.jpg'),
 PosixPath('Database/GoodPLR_0.442_8469.jpg'),
 PosixPath('Database/GoodPLR_0.491_4330.jpg'),
 PosixPath('Database/GoodPLR_0.471_462.jpg'),
 PosixPath('Database/GoodPLR_0.472_7153.jpg'),
 PosixPath('Database/GoodPLR_0.358_9380.jpg'),
 PosixPath('Database/GoodPLR_0.426_4216.jpg'),
 PosixPath('Database/GoodPLR_0.238_1857.jpg'),
 PosixPath('Database/GoodPLR_0.426_4146.jpg'),
 PosixPath('Database/GoodPLR_0.441_5527.jpg'),
 PosixPath('Database/GoodPLR_0.537_4572.jpg'),
 PosixPath('Database/GoodPLR_0.327_121.jpg'),
 PosixPath('Database/GoodPLR_0.412_6757.jpg'),
 PosixPath('Database/GoodPLR_0.35_4755.jpg'),
 PosixPath('Database/GoodPLR_0.391_6700.jpg'),
 PosixPath('Database/GoodPLR_0.408_5190.jpg'),
 PosixPath('Database/GoodPLR_0.442_2803.jpg'),
 PosixPath('Database/GoodPLR_0.462_1921.jpg'),
 PosixPath('Database/GoodPLR_0.417_3765.jpg'),
 PosixPath('Database/GoodPLR_0.446_5492.jpg'),
 PosixPath('Database/GoodPLR_0.438_8798.jpg'),
 PosixPath('Database/GoodPLR_0.537_8547.jpg'),
 PosixPath('Database/GoodPLR_0.404_7475.jpg'),
 PosixPath('Database/GoodPLR_0.481_7662.jpg'),
 PosixPath('Database/GoodPLR_0.439_7177.jpg'),
 PosixPath('Database/GoodPLR_0.455_2387.jpg'),
 PosixPath('Database/GoodPLR_0.473_3151.jpg'),
 PosixPath('Database/GoodPLR_0.365_7357.jpg'),
 PosixPath('Database/GoodPLR_0.418_53.jpg'),
 PosixPath('Database/GoodPLR_0.442_1477.jpg'),
 PosixPath('Database/GoodPLR_0.527_4367.jpg'),
 PosixPath('Database/GoodPLR_0.478_1642.jpg'),
 PosixPath('Database/GoodPLR_0.404_2266.jpg'),
 PosixPath('Database/GoodPLR_0.46_8846.jpg'),
 PosixPath('Database/GoodPLR_0.468_1945.jpg'),
 PosixPath('Database/GoodPLR_0.449_1899.jpg'),
 PosixPath('Database/GoodPLR_0.509_704.jpg'),
 PosixPath('Database/GoodPLR_0.522_2888.jpg'),
 PosixPath('Database/GoodPLR_0.357_238.jpg'),
 PosixPath('Database/GoodPLR_0.429_3697.jpg'),
 PosixPath('Database/GoodPLR_0.529_9426.jpg'),
 PosixPath('Database/GoodPLR_0.472_7543.jpg'),
 PosixPath('Database/GoodPLR_0.479_3398.jpg'),
 PosixPath('Database/GoodPLR_0.48_7067.jpg'),
 PosixPath('Database/GoodPLR_0.451_9265.jpg'),
 PosixPath('Database/GoodPLR_0.345_9173.jpg'),
 PosixPath('Database/GoodPLR_0.377_7544.jpg'),
 PosixPath('Database/GoodPLR_0.483_8133.jpg'),
 PosixPath('Database/GoodPLR_0.5_5843.jpg'),
 PosixPath('Database/GoodPLR_0.385_4206.jpg'),
 PosixPath('Database/GoodPLR_0.365_9072.jpg'),
 PosixPath('Database/GoodPLR_0.489_666.jpg'),
 PosixPath('Database/GoodPLR_0.468_5861.jpg'),
 PosixPath('Database/GoodPLR_0.39_9028.jpg'),
 PosixPath('Database/GoodPLR_0.463_9787.jpg'),
 PosixPath('Database/models'),
 PosixPath('Database/GoodPLR_0.389_6505.jpg'),
 PosixPath('Database/GoodPLR_0.457_3367.jpg'),
 PosixPath('Database/GoodPLR_0.396_4852.jpg'),
 PosixPath('Database/GoodPLR_0.32_3518.jpg'),
 PosixPath('Database/GoodPLR_0.473_6279.jpg'),
 PosixPath('Database/GoodPLR_0.489_619.jpg'),
 PosixPath('Database/GoodPLR_0.357_8261.jpg'),
 PosixPath('Database/GoodPLR_0.4_3232.jpg'),
 PosixPath('Database/GoodPLR_0.446_24.jpg'),
 PosixPath('Database/GoodPLR_0.418_2412.jpg'),
 PosixPath('Database/GoodPLR_0.4_2501.jpg'),
 PosixPath('Database/.ipynb_checkpoints'),
 PosixPath('Database/GoodPLR_0.434_266.jpg'),
 PosixPath('Database/GoodPLR_0.4_1797.jpg'),
 PosixPath('Database/GoodPLR_0.315_5310.jpg'),
 PosixPath('Database/GoodPLR_0.462_200.jpg'),
 PosixPath('Database/GoodPLR_0.365_5661.jpg'),
 PosixPath('Database/GoodPLR_0.442_1653.jpg'),
 PosixPath('Database/GoodPLR_0.5_5120.jpg'),
 PosixPath('Database/GoodPLR_0.52_6453.jpg'),
 PosixPath('Database/GoodPLR_0.421_815.jpg'),
 PosixPath('Database/GoodPLR_0.5_2574.jpg'),
 PosixPath('Database/GoodPLR_0.31_7665.jpg'),
 PosixPath('Database/GoodPLR_0.32_791.jpg'),
 PosixPath('Database/GoodPLR_0.345_6004.jpg'),
 PosixPath('Database/GoodPLR_0.48_4147.jpg'),
 PosixPath('Database/GoodPLR_0.365_7663.jpg'),
 PosixPath('Database/GoodPLR_0.442_9326.jpg'),
 PosixPath('Database/GoodPLR_0.442_9435.jpg'),
 PosixPath('Database/GoodPLR_0.49_192.jpg'),
 PosixPath('Database/GoodPLR_0.39_8593.jpg'),
 PosixPath('Database/GoodPLR_0.42_3708.jpg'),
 PosixPath('Database/GoodPLR_0.479_4228.jpg'),
 PosixPath('Database/GoodPLR_0.426_654.jpg'),
 PosixPath('Database/GoodPLR_0.327_9716.jpg'),
 PosixPath('Database/GoodPLR_0.492_4189.jpg'),
 PosixPath('Database/GoodPLR_0.4_8430.jpg'),
 PosixPath('Database/GoodPLR_0.46_8323.jpg'),
 PosixPath('Database/GoodPLR_0.222_2094.jpg'),
 PosixPath('Database/GoodPLR_0.529_7364.jpg'),
 PosixPath('Database/GoodPLR_0.345_2954.jpg'),
 PosixPath('Database/GoodPLR_0.42_4819.jpg'),
 PosixPath('Database/GoodPLR_0.482_5835.jpg'),
 PosixPath('Database/GoodPLR_0.412_1458.jpg'),
 PosixPath('Database/GoodPLR_0.444_2873.jpg'),
 PosixPath('Database/GoodPLR_0.404_4915.jpg'),
 PosixPath('Database/GoodPLR_0.532_7177.jpg'),
 PosixPath('Database/GoodPLR_0.418_2342.jpg'),
 PosixPath('Database/GoodPLR_0.396_97.jpg'),
 PosixPath('Database/GoodPLR_0.25_2925.jpg'),
 PosixPath('Database/GoodPLR_0.448_3465.jpg'),
 PosixPath('Database/GoodPLR_0.463_8105.jpg'),
 PosixPath('Database/GoodPLR_0.404_3682.jpg'),
 PosixPath('Database/GoodPLR_0.345_8376.jpg'),
 PosixPath('Database/GoodPLR_0.46_3063.jpg'),
 PosixPath('Database/GoodPLR_0.389_470.jpg'),
 PosixPath('Database/GoodPLR_0.442_9570.jpg'),
 PosixPath('Database/GoodPLR_0.455_3528.jpg'),
 PosixPath('Database/GoodPLR_0.431_4040.jpg'),
 PosixPath('Database/GoodPLR_0.426_2715.jpg'),
 PosixPath('Database/GoodPLR_0.415_1981.jpg'),
 PosixPath('Database/GoodPLR_0.42_3102.jpg'),
 PosixPath('Database/GoodPLR_0.4_10.jpg'),
 PosixPath('Database/GoodPLR_0.418_7903.jpg'),
 PosixPath('Database/GoodPLR_0.421_4499.jpg'),
 PosixPath('Database/GoodPLR_0.489_8875.jpg')]
In [5]:
fnames = get_image_files(path)
fnames[:5]
Out[5]:
[PosixPath('Database/GoodPLR_0.404_7581.jpg'),
 PosixPath('Database/GoodPLR_0.433_2440.jpg'),
 PosixPath('Database/GoodPLR_0.352_5594.jpg'),
 PosixPath('Database/GoodPLR_0.46_5072.jpg'),
 PosixPath('Database/GoodPLR_0.37_914.jpg')]

variable a will determine the nearest digit that the float will be rounded to.

small a will result in many classes

def round_nearest(x, a): return round(x / a) * a

In [6]:
#pat = r'/([^/]+)_\d+.jpg$'
def get_float_labels(y):
    return (float(y.parts[-1].split('_')[1]))
    
In [ ]:
??ImageDataBunch.from_name_func
In [7]:
np.random.seed(42)
bs = 40
bs = 40
tfms = get_transforms(do_flip=False)
fnames = get_image_files(path)
fnames
Out[7]:
[PosixPath('Database/GoodPLR_0.404_7581.jpg'),
 PosixPath('Database/GoodPLR_0.433_2440.jpg'),
 PosixPath('Database/GoodPLR_0.352_5594.jpg'),
 PosixPath('Database/GoodPLR_0.46_5072.jpg'),
 PosixPath('Database/GoodPLR_0.37_914.jpg'),
 PosixPath('Database/GoodPLR_0.404_840.jpg'),
 PosixPath('Database/GoodPLR_0.404_9135.jpg'),
 PosixPath('Database/GoodPLR_0.509_6291.jpg'),
 PosixPath('Database/GoodPLR_0.389_3233.jpg'),
 PosixPath('Database/GoodPLR_0.46_1675.jpg'),
 PosixPath('Database/GoodPLR_0.391_4683.jpg'),
 PosixPath('Database/GoodPLR_0.439_7106.jpg'),
 PosixPath('Database/GoodPLR_0.442_3577.jpg'),
 PosixPath('Database/GoodPLR_0.259_2725.jpg'),
 PosixPath('Database/GoodPLR_0.463_3786.jpg'),
 PosixPath('Database/GoodPLR_0.52_3953.jpg'),
 PosixPath('Database/GoodPLR_0.434_7464.jpg'),
 PosixPath('Database/GoodPLR_0.349_8029.jpg'),
 PosixPath('Database/GoodPLR_0.421_4339.jpg'),
 PosixPath('Database/GoodPLR_0.339_9193.jpg'),
 PosixPath('Database/GoodPLR_0.404_3004.jpg'),
 PosixPath('Database/GoodPLR_0.36_8549.jpg'),
 PosixPath('Database/GoodPLR_0.362_2952.jpg'),
 PosixPath('Database/GoodPLR_0.37_478.jpg'),
 PosixPath('Database/GoodPLR_0.421_1363.jpg'),
 PosixPath('Database/GoodPLR_0.46_2342.jpg'),
 PosixPath('Database/GoodPLR_0.46_6261.jpg'),
 PosixPath('Database/GoodPLR_0.341_3736.jpg'),
 PosixPath('Database/GoodPLR_0.472_1775.jpg'),
 PosixPath('Database/GoodPLR_0.396_2996.jpg'),
 PosixPath('Database/GoodPLR_0.3_7677.jpg'),
 PosixPath('Database/GoodPLR_0.611_8898.jpg'),
 PosixPath('Database/GoodPLR_0.545_1715.jpg'),
 PosixPath('Database/GoodPLR_0.404_4433.jpg'),
 PosixPath('Database/GoodPLR_0.451_9843.jpg'),
 PosixPath('Database/GoodPLR_0.469_621.jpg'),
 PosixPath('Database/GoodPLR_0.457_649.jpg'),
 PosixPath('Database/GoodPLR_0.451_3790.jpg'),
 PosixPath('Database/GoodPLR_0.527_3408.jpg'),
 PosixPath('Database/GoodPLR_0.412_8090.jpg'),
 PosixPath('Database/GoodPLR_0.439_5332.jpg'),
 PosixPath('Database/GoodPLR_0.509_528.jpg'),
 PosixPath('Database/GoodPLR_0.453_97.jpg'),
 PosixPath('Database/GoodPLR_0.421_5869.jpg'),
 PosixPath('Database/GoodPLR_0.358_9200.jpg'),
 PosixPath('Database/GoodPLR_0.385_8919.jpg'),
 PosixPath('Database/GoodPLR_0.433_4170.jpg'),
 PosixPath('Database/GoodPLR_0.294_7891.jpg'),
 PosixPath('Database/GoodPLR_0.345_4944.jpg'),
 PosixPath('Database/GoodPLR_0.429_3374.jpg'),
 PosixPath('Database/GoodPLR_0.345_1363.jpg'),
 PosixPath('Database/GoodPLR_0.358_2210.jpg'),
 PosixPath('Database/GoodPLR_0.358_3472.jpg'),
 PosixPath('Database/GoodPLR_0.42_186.jpg'),
 PosixPath('Database/GoodPLR_0.35_9730.jpg'),
 PosixPath('Database/GoodPLR_0.345_2904.jpg'),
 PosixPath('Database/GoodPLR_0.396_866.jpg'),
 PosixPath('Database/GoodPLR_0.321_2785.jpg'),
 PosixPath('Database/GoodPLR_0.472_7271.jpg'),
 PosixPath('Database/GoodPLR_0.383_4186.jpg'),
 PosixPath('Database/GoodPLR_0.256_7193.jpg'),
 PosixPath('Database/GoodPLR_0.5_8621.jpg'),
 PosixPath('Database/GoodPLR_0.389_387.jpg'),
 PosixPath('Database/GoodPLR_0.468_8549.jpg'),
 PosixPath('Database/GoodPLR_0.393_4466.jpg'),
 PosixPath('Database/GoodPLR_0.446_2972.jpg'),
 PosixPath('Database/GoodPLR_0.56_5872.jpg'),
 PosixPath('Database/GoodPLR_0.48_5767.jpg'),
 PosixPath('Database/GoodPLR_0.4_3042.jpg'),
 PosixPath('Database/GoodPLR_0.434_2704.jpg'),
 PosixPath('Database/GoodPLR_0.442_8469.jpg'),
 PosixPath('Database/GoodPLR_0.491_4330.jpg'),
 PosixPath('Database/GoodPLR_0.471_462.jpg'),
 PosixPath('Database/GoodPLR_0.472_7153.jpg'),
 PosixPath('Database/GoodPLR_0.358_9380.jpg'),
 PosixPath('Database/GoodPLR_0.426_4216.jpg'),
 PosixPath('Database/GoodPLR_0.238_1857.jpg'),
 PosixPath('Database/GoodPLR_0.426_4146.jpg'),
 PosixPath('Database/GoodPLR_0.441_5527.jpg'),
 PosixPath('Database/GoodPLR_0.537_4572.jpg'),
 PosixPath('Database/GoodPLR_0.327_121.jpg'),
 PosixPath('Database/GoodPLR_0.412_6757.jpg'),
 PosixPath('Database/GoodPLR_0.35_4755.jpg'),
 PosixPath('Database/GoodPLR_0.391_6700.jpg'),
 PosixPath('Database/GoodPLR_0.408_5190.jpg'),
 PosixPath('Database/GoodPLR_0.442_2803.jpg'),
 PosixPath('Database/GoodPLR_0.462_1921.jpg'),
 PosixPath('Database/GoodPLR_0.417_3765.jpg'),
 PosixPath('Database/GoodPLR_0.446_5492.jpg'),
 PosixPath('Database/GoodPLR_0.438_8798.jpg'),
 PosixPath('Database/GoodPLR_0.537_8547.jpg'),
 PosixPath('Database/GoodPLR_0.404_7475.jpg'),
 PosixPath('Database/GoodPLR_0.481_7662.jpg'),
 PosixPath('Database/GoodPLR_0.439_7177.jpg'),
 PosixPath('Database/GoodPLR_0.455_2387.jpg'),
 PosixPath('Database/GoodPLR_0.473_3151.jpg'),
 PosixPath('Database/GoodPLR_0.365_7357.jpg'),
 PosixPath('Database/GoodPLR_0.418_53.jpg'),
 PosixPath('Database/GoodPLR_0.442_1477.jpg'),
 PosixPath('Database/GoodPLR_0.527_4367.jpg'),
 PosixPath('Database/GoodPLR_0.478_1642.jpg'),
 PosixPath('Database/GoodPLR_0.404_2266.jpg'),
 PosixPath('Database/GoodPLR_0.46_8846.jpg'),
 PosixPath('Database/GoodPLR_0.468_1945.jpg'),
 PosixPath('Database/GoodPLR_0.449_1899.jpg'),
 PosixPath('Database/GoodPLR_0.509_704.jpg'),
 PosixPath('Database/GoodPLR_0.522_2888.jpg'),
 PosixPath('Database/GoodPLR_0.357_238.jpg'),
 PosixPath('Database/GoodPLR_0.429_3697.jpg'),
 PosixPath('Database/GoodPLR_0.529_9426.jpg'),
 PosixPath('Database/GoodPLR_0.472_7543.jpg'),
 PosixPath('Database/GoodPLR_0.479_3398.jpg'),
 PosixPath('Database/GoodPLR_0.48_7067.jpg'),
 PosixPath('Database/GoodPLR_0.451_9265.jpg'),
 PosixPath('Database/GoodPLR_0.345_9173.jpg'),
 PosixPath('Database/GoodPLR_0.377_7544.jpg'),
 PosixPath('Database/GoodPLR_0.483_8133.jpg'),
 PosixPath('Database/GoodPLR_0.5_5843.jpg'),
 PosixPath('Database/GoodPLR_0.385_4206.jpg'),
 PosixPath('Database/GoodPLR_0.365_9072.jpg'),
 PosixPath('Database/GoodPLR_0.489_666.jpg'),
 PosixPath('Database/GoodPLR_0.468_5861.jpg'),
 PosixPath('Database/GoodPLR_0.39_9028.jpg'),
 PosixPath('Database/GoodPLR_0.463_9787.jpg'),
 PosixPath('Database/GoodPLR_0.389_6505.jpg'),
 PosixPath('Database/GoodPLR_0.457_3367.jpg'),
 PosixPath('Database/GoodPLR_0.396_4852.jpg'),
 PosixPath('Database/GoodPLR_0.32_3518.jpg'),
 PosixPath('Database/GoodPLR_0.473_6279.jpg'),
 PosixPath('Database/GoodPLR_0.489_619.jpg'),
 PosixPath('Database/GoodPLR_0.357_8261.jpg'),
 PosixPath('Database/GoodPLR_0.4_3232.jpg'),
 PosixPath('Database/GoodPLR_0.446_24.jpg'),
 PosixPath('Database/GoodPLR_0.418_2412.jpg'),
 PosixPath('Database/GoodPLR_0.4_2501.jpg'),
 PosixPath('Database/GoodPLR_0.434_266.jpg'),
 PosixPath('Database/GoodPLR_0.4_1797.jpg'),
 PosixPath('Database/GoodPLR_0.315_5310.jpg'),
 PosixPath('Database/GoodPLR_0.462_200.jpg'),
 PosixPath('Database/GoodPLR_0.365_5661.jpg'),
 PosixPath('Database/GoodPLR_0.442_1653.jpg'),
 PosixPath('Database/GoodPLR_0.5_5120.jpg'),
 PosixPath('Database/GoodPLR_0.52_6453.jpg'),
 PosixPath('Database/GoodPLR_0.421_815.jpg'),
 PosixPath('Database/GoodPLR_0.5_2574.jpg'),
 PosixPath('Database/GoodPLR_0.31_7665.jpg'),
 PosixPath('Database/GoodPLR_0.32_791.jpg'),
 PosixPath('Database/GoodPLR_0.345_6004.jpg'),
 PosixPath('Database/GoodPLR_0.48_4147.jpg'),
 PosixPath('Database/GoodPLR_0.365_7663.jpg'),
 PosixPath('Database/GoodPLR_0.442_9326.jpg'),
 PosixPath('Database/GoodPLR_0.442_9435.jpg'),
 PosixPath('Database/GoodPLR_0.49_192.jpg'),
 PosixPath('Database/GoodPLR_0.39_8593.jpg'),
 PosixPath('Database/GoodPLR_0.42_3708.jpg'),
 PosixPath('Database/GoodPLR_0.479_4228.jpg'),
 PosixPath('Database/GoodPLR_0.426_654.jpg'),
 PosixPath('Database/GoodPLR_0.327_9716.jpg'),
 PosixPath('Database/GoodPLR_0.492_4189.jpg'),
 PosixPath('Database/GoodPLR_0.4_8430.jpg'),
 PosixPath('Database/GoodPLR_0.46_8323.jpg'),
 PosixPath('Database/GoodPLR_0.222_2094.jpg'),
 PosixPath('Database/GoodPLR_0.529_7364.jpg'),
 PosixPath('Database/GoodPLR_0.345_2954.jpg'),
 PosixPath('Database/GoodPLR_0.42_4819.jpg'),
 PosixPath('Database/GoodPLR_0.482_5835.jpg'),
 PosixPath('Database/GoodPLR_0.412_1458.jpg'),
 PosixPath('Database/GoodPLR_0.444_2873.jpg'),
 PosixPath('Database/GoodPLR_0.404_4915.jpg'),
 PosixPath('Database/GoodPLR_0.532_7177.jpg'),
 PosixPath('Database/GoodPLR_0.418_2342.jpg'),
 PosixPath('Database/GoodPLR_0.396_97.jpg'),
 PosixPath('Database/GoodPLR_0.25_2925.jpg'),
 PosixPath('Database/GoodPLR_0.448_3465.jpg'),
 PosixPath('Database/GoodPLR_0.463_8105.jpg'),
 PosixPath('Database/GoodPLR_0.404_3682.jpg'),
 PosixPath('Database/GoodPLR_0.345_8376.jpg'),
 PosixPath('Database/GoodPLR_0.46_3063.jpg'),
 PosixPath('Database/GoodPLR_0.389_470.jpg'),
 PosixPath('Database/GoodPLR_0.442_9570.jpg'),
 PosixPath('Database/GoodPLR_0.455_3528.jpg'),
 PosixPath('Database/GoodPLR_0.431_4040.jpg'),
 PosixPath('Database/GoodPLR_0.426_2715.jpg'),
 PosixPath('Database/GoodPLR_0.415_1981.jpg'),
 PosixPath('Database/GoodPLR_0.42_3102.jpg'),
 PosixPath('Database/GoodPLR_0.4_10.jpg'),
 PosixPath('Database/GoodPLR_0.418_7903.jpg'),
 PosixPath('Database/GoodPLR_0.421_4499.jpg'),
 PosixPath('Database/GoodPLR_0.489_8875.jpg')]

data = ImageDataBunch.from_name_func(path, fnames, get_float_labels, ds_tfms=get_transforms(), size=224, ).normalize(imagenet_stats)

In [8]:
data = (ImageItemList(fnames)
        .random_split_by_pct(0.3)
        .label_from_func(get_float_labels)
        .transform(tfms, size=224)
        .databunch())
In [9]:
data.bs = bs
In [10]:
learn = create_cnn(data, models.resnet50, metrics=[mean_squared_error])
In [11]:
data.show_batch(rows=3, figsize=(7,6))

learn = create_cnn(data, models.resnet50,metrics=error_rate)

In [ ]:
learn.model
In [12]:
learn.fit_one_cycle(4)
Total time: 00:26

epoch train_loss valid_loss mean_squared_error
1 1.470903 0.185693 0.185693
2 1.552391 4.897641 4.897641
3 2.182579 2.469059 2.469059
4 2.270307 1.030308 1.030308
In [13]:
interp = ClassificationInterpretation.from_learner(learn)
In [14]:
interp.plot_confusion_matrix(figsize=(12,12), dpi=60)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-14-d745160313a7> in <module>
----> 1 interp.plot_confusion_matrix(figsize=(12,12), dpi=60)

~/anaconda3/lib/python3.7/site-packages/fastai/train.py in plot_confusion_matrix(self, normalize, title, cmap, slice_size, norm_dec, **kwargs)
    127         "Plot the confusion matrix, with `title` and using `cmap`."
    128         # This function is mainly copied from the sklearn docs
--> 129         cm = self.confusion_matrix(slice_size=slice_size)
    130         if normalize: cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
    131         plt.figure(**kwargs)

~/anaconda3/lib/python3.7/site-packages/fastai/train.py in confusion_matrix(self, slice_size)
    119             for i in range(0, self.y_true.shape[0], slice_size):
    120                 cm_slice = ((self.pred_class[i:i+slice_size]==x[:,None])
--> 121                             & (self.y_true[i:i+slice_size]==x[:,None,None])).sum(2)
    122                 torch.add(cm, cm_slice, out=cm)
    123         return to_np(cm)

RuntimeError: Expected object of scalar type Float but got scalar type Long for argument #2 'other'
In [ ]:
learn.lr_find()
In [ ]:
learn.recorder.plot()
In [15]:
learn.save('PLRstage1')
In [ ]:
learn.unfreeze()
In [ ]:
learn.fit_one_cycle(2, max_lr=slice(3e-4,2e-2))
In [ ]:
learn.save('stage-2')
In [ ]:
learn.load('PLRstage1')
In [27]:
import os, random, math
In [57]:
randomchoice = random.choice(os.listdir("/home/ubuntu/Eyetrain/Database/"))
randomchoice
Out[57]:
'GoodPLR_0.345_2954.jpg'
In [58]:
img = open_image('/home/ubuntu/Eyetrain/Database/'+randomchoice)
img
Out[58]:
In [59]:
log_preds = learn.predict(img)
log_preds
Out[59]:
(FloatItem [-0.513865], tensor([-0.5139]), tensor([-0.5139]))
In [55]:
exponent = float(str(log_preds[0]).split('[')[1].split(']')[0])
In [56]:
exp(exponent)
Out[56]:
0.5491525539640835
In [ ]: