{"cells":[{"metadata":{"trusted":true,"_uuid":"a46698f49f093cd7aaa3c6617d9545631b9de5d3"},"cell_type":"code","source":"img_path = '../input/images/hedgehog.jpg'","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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\n\nimage_size = 224 \n\n\"\"\"\n    Cleans up image before testing\n\"\"\"\ndef pre_process_image(img_path, img_height=image_size, img_width=image_size):\n    img = [load_img(img_path, target_size=(img_height, img_width))]\n    img_array = np.array([img_to_array(img[0])])\n    output = preprocess_input(img_array)\n    return output","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"from tensorflow.python.keras.applications import ResNet50\n\nmodel = ResNet50(weights='../input/resnet50/resnet50_weights_tf_dim_ordering_tf_kernels.h5')\ntest_data = pre_process_image(img_path)\npredictions = model.predict(test_data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"66bec9b3b6f366f1b4f58ffe4756fdf5ce32e574"},"cell_type":"code","source":"from learntools.deep_learning.decode_predictions import decode_predictions\nfrom IPython.display import Image, display\n\nlabels = decode_predictions(predictions, top=4, class_list_path='../input/resnet50/imagenet_class_index.json')\n\ndisplay(Image(img_path))\n\nguess = labels[0][0][1]\npercent = float(labels[0][0][2]) * 100\n\nprint(\"Results for \" + img_path + \": \")\nprint(guess + \": \" + str(percent) + \" %\")","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}