In [1]:
%reload_ext autoreload
%autoreload 2
%matplotlib inline
In [2]:
from fastai.vision import *
from fastai.imports import *
from fastai.metrics import error_rate
In [3]:
PATH = Path("../../data/lv_imgs/")
In [4]:
!ls {PATH}
models	train
In [5]:
!ls {PATH}/train
fake_bags  real_bags
In [6]:
!ls {PATH}/train/fake_bags | wc -l
51
In [7]:
!ls {PATH}/train/real_bags | wc -l
70
In [8]:
sample_img = !ls {PATH}/train/fake_bags | head -n 1
#sample_img
img = plt.imread(f'{PATH}/train/fake_bags/{sample_img[0]}')
plt.imshow(img)
Out[8]:
<matplotlib.image.AxesImage at 0x7fe0308f64e0>
In [28]:
np.random.seed(561)
data = ImageDataBunch.from_folder(PATH, 
                                  ds_tfms=get_transforms(), 
                                  size=224,
                                  valid_pct= .25,
                                  bs=16
                                  ).normalize(imagenet_stats)
In [29]:
learn = create_cnn(data, 
                   models.resnet50, 
                   metrics=error_rate,
                   ps=.7)
In [30]:
learn.fit_one_cycle(4,
                    max_lr=slice(3e-05, 3e-04))
Total time: 00:12

epoch train_loss valid_loss error_rate
1 1.106430 0.649481 0.366667
2 1.373133 0.652975 0.466667
3 1.250432 0.668808 0.400000
4 1.103542 0.672520 0.400000
In [12]:
interp = ClassificationInterpretation.from_learner(learn)
losses,idxs=interp.top_losses()
interp.plot_top_losses(9)
In [13]:
interp.plot_confusion_matrix()
In [31]:
learn.unfreeze()
In [14]:
learn.lr_find()
learn.recorder.plot()
LR Finder is complete, type {learner_name}.recorder.plot() to see the graph.
In [32]:
learn.fit_one_cycle(2, 
                    max_lr=3e-4)
Total time: 00:07

epoch train_loss valid_loss error_rate
1 0.910160 0.800928 0.400000
2 0.762213 0.756685 0.366667
In [ ]:
interp = ClassificationInterpretation.from_learner(learn)
losses,idxs=interp.top_losses()
In [ ]:
interp.plot_confusion_matrix()
In [ ]:
interp.plot_top_losses(9)
In [ ]:
from fastai.widgets import *
In [ ]:
ds, idxs = DatasetFormatter().from_toplosses(learn, ds_type=DatasetType.Train)
In [ ]:
ImageCleaner(ds, idxs, PATH)