{"cells":[{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","collapsed":true,"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":false},"cell_type":"markdown","source":"# Intro\n\nHere we are going to use a pretrained Resnt50 model, one of the best model in computer vision. We will use TensorFlow and Keras to implement this model to detect the breeds of dog. We don't have to train this model, because it's already trained on ImageNet data. \n\nNote - Here we can't build a model from scatch because we have very small dataset of 120 images for training, so we must have to use some pretrained model with all the weights already defined."},{"metadata":{"_uuid":"ebe80713531dcf4828829f22b31d9a4746705cda"},"cell_type":"markdown","source":"## Creating model with pretrained weight file."},{"metadata":{"trusted":true,"_uuid":"d9856cc9056f56ffb03d6a81b9f9561e172c7a05"},"cell_type":"code","source":"from tensorflow.python.keras.applications import ResNet50\n\nmy_model = ResNet50(weights='../input/resnet50/resnet50_weights_tf_dim_ordering_tf_kernels.h5')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"415f93326ccdaff3f6c7d197e975b4c29ae17d62"},"cell_type":"markdown","source":"## Reading and Pre-processing images for modelling"},{"metadata":{"trusted":true,"_uuid":"d5fc0465659fc8d57e11b2838ea2bb3c3679dbb4"},"cell_type":"code","source":"import numpy as np\nfrom tensorflow.python.keras.applications.resnet50 import preprocess_input\nfrom tensorflow.python.keras.preprocessing.image import load_img, img_to_array\nfrom os.path import join\n\nimage_dir = '../input/dog-breed-identification/train/'\nimg_paths = [join(image_dir, filename) for filename in \n                           ['0246f44bb123ce3f91c939861eb97fb7.jpg',\n                            '84728e78632c0910a69d33f82e62638c.jpg',\n                            '8825e914555803f4c67b26593c9d5aff.jpg',\n                            '91a5e8db15bccfb6cfa2df5e8b95ec03.jpg']]\n\nimage_size = 224\n\ndef read_and_prep_images(img_paths, img_height=image_size, img_width=image_size):\n    imgs = [load_img(img_path, target_size=(img_height, img_width)) for img_path in img_paths]\n    img_array = np.array([img_to_array(img) for img in imgs])\n    output = preprocess_input(img_array)\n    return(output)\n\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7406cfd6bd444d2bb833a94088823e8a73f793fe"},"cell_type":"markdown","source":"## Making Predictions\n"},{"metadata":{"trusted":true,"_uuid":"61e86efd2dbbdef1b680183f60c7abaeef0c6580"},"cell_type":"code","source":"test_data = read_and_prep_images(img_paths)\npreds = my_model.predict(test_data)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f1ae1e656bdf4b31e630c3cd2c8d4a196aa415f2"},"cell_type":"markdown","source":"## Visualizing Predictions"},{"metadata":{"trusted":true,"_uuid":"1a91a715d5341b6fe03a186f11c7a1a29595db80"},"cell_type":"code","source":"from learntools.deep_learning.decode_predictions import decode_predictions\nfrom IPython.display import Image, display\n\nmost_likely_labels = decode_predictions(preds, top=3)\n\nfor i, img_path in enumerate(img_paths):\n    display(Image(img_path))\n    print(most_likely_labels[i])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ffdaa26073a6361f9c555f8bddab4c20f9781560"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}