<jupyter_start><jupyter_text>Import the required packages<jupyter_code>from fastai.vision import *<jupyter_output><empty_output><jupyter_text>Create two variable folder & files<jupyter_code>folder = 'kids'
file = 'kids.txt'
folder = 'adults'
file = 'adults.txt'<jupyter_output><empty_output><jupyter_text>Connectiong Google Drive to our notebook<jupyter_code>from google.colab import drive
drive.mount('/content/gdrive', force_remount=True)
root_dir = "/content/gdrive/My Drive/"
base_dir = root_dir + 'fastai-v3/'<jupyter_output>Mounted at /content/gdrive<jupyter_text>Creating folders for images of kids and adults<jupyter_code>path = Path(base_dir + 'data/humans')
dest = path/folder
dest.mkdir(parents=True, exist_ok=True)<jupyter_output><empty_output><jupyter_text>Command to download the images<jupyter_code>download_images(path/file, dest, max_pics=200)<jupyter_output><empty_output><jupyter_text>Create the required classes (here kids & adults)<jupyter_code>classes = ['kids', 'adults']<jupyter_output><empty_output><jupyter_text>Deleting the images that are not fine or corrupted<jupyter_code>for c in classes:
    print(c)
    verify_images(path/c, delete=True, max_size=500)<jupyter_output><empty_output><jupyter_text>Create an ImageDataBunch<jupyter_code>np.random.seed(42)
data = ImageDataBunch.from_folder(path, train=".", valid_pct=0.2,
        ds_tfms=get_transforms(), size=224, num_workers=4).normalize(imagenet_stats)<jupyter_output><empty_output><jupyter_text>Seeing the content of classes<jupyter_code>data.classes<jupyter_output><empty_output><jupyter_text>Lets see the images in the classes<jupyter_code>data.show_batch(rows=3, figsize=(7,8))<jupyter_output><empty_output><jupyter_text>Seeing the contents such as classes, data, training data, validation data<jupyter_code>data.classes, data.c, len(data.train_ds), len(data.valid_ds)<jupyter_output><empty_output><jupyter_text>**Training the Model** Create a convolutionalneuralnetwork ;) using resnet34<jupyter_code>learn = cnn_learner(data, models.resnet34, metrics=error_rate)<jupyter_output><empty_output><jupyter_text>Fit it to see the accuracy<jupyter_code>learn.fit_one_cycle(4)<jupyter_output><empty_output><jupyter_text>save it<jupyter_code>learn.save('stage-1')<jupyter_output><empty_output><jupyter_text>**Fine Tuning the Model**<jupyter_code>learn.unfreeze()
learn.lr_find()
learn.recorder.plot()
learn.fit_one_cycle(2, max_lr=slice(3e-5,3e-4))
learn.save('stage-2')<jupyter_output><empty_output><jupyter_text>**Loading models to see which works better!!!**<jupyter_code>learn.load('stage-1');
#learn.load('stage-2');<jupyter_output><empty_output><jupyter_text>**Interpretation of our model**<jupyter_code>interp = ClassificationInterpretation.from_learner(learn)
interp.plot_confusion_matrix()<jupyter_output><empty_output><jupyter_text>**Putting the model into production!!!**<jupyter_code>learn.export()
defaults.device = torch.device('cpu')
img = open_image(path/'kids'/'00000025.jpg')
img
learn = load_learner(path)
pred_class,pred_idx,outputs = learn.predict(img)
pred_class<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup