<jupyter_start><jupyter_text>we will use the Oxford-IIIT Pet Dataset that contains images of cats and dogs of 37 different breeds. We will first show how to build a simple cat-vs-dog classifier, then a little bit more advanced model that can classify all breeds.This code download the datasets amd only do this once.<jupyter_code>#Path
path.ls()
#Getting all files
image_files = get_image_files(path/"images")<jupyter_output><empty_output><jupyter_text>get_image_file() gets all the images in one folder recursively<jupyter_code>def label_func(f): return f[0].isupper()
dls = ImageDataLoaders.from_name_func(path, image_files, label_func,item_tfms=Resize(224))<jupyter_output><empty_output><jupyter_text>to get our data ready I have passed it into the dataloader<jupyter_code>dls.show_batch(figsize=(16,7))<jupyter_output><empty_output><jupyter_text>I have checked if everythigs is fine with show_batch method True is for cat and False is for Dog<jupyter_code>learn = cnn_learner(dls, resnet34,metrics=error_rate)
learn.model<jupyter_output><empty_output><jupyter_text>Here above download ResNet model which was pretained in imagenetI have also shows the model layers<jupyter_code>learn.fine_tune(1)<jupyter_output><empty_output><jupyter_text>i have created a Learner, which is a fastai object that combines the data and a model for training, and uses transfer learning to fine tune a pretrained model in just two lines of code we get a model with an error rate of 0.1%<jupyter_code>learn.show_results()
files = "/content/cats.jpg"
learn.predict(files)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07648546144121365, 'fraction_numerical': 0.008849557522123894, 'mean_word_length': 7.420212765957447, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '475934', 'license': 'MIT', 'n_tokens_mistral': 523, 'n_tokens_neox': 506, 'n_words': 165, 'path': 'CatsvsDogs.ipynb', 'repo_name': 'Maze-lol/DogvsCatClassification', 'size': '1582'}