{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":7327,"databundleVersionId":861871,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":9900,"sourceType":"datasetVersion","datasetId":6209}],"dockerImageVersionId":30919,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from os.path import join\nimport numpy as np\nfrom tensorflow.keras.applications.resnet50 import preprocess_input\nfrom tensorflow.keras.preprocessing.image import load_img, img_to_array\nfrom tensorflow.keras.applications import ResNet50","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T07:48:33.749616Z","iopub.execute_input":"2025-03-13T07:48:33.749908Z","iopub.status.idle":"2025-03-13T07:48:33.753859Z","shell.execute_reply.started":"2025-03-13T07:48:33.749885Z","shell.execute_reply":"2025-03-13T07:48:33.753124Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_dir = '../input/dog-breed-identification/train/'\nimg_paths = [join(image_dir, filename) for filename in \n                           ['0c8fe33bd89646b678f6b2891df8a1c6.jpg',\n                            '0c3b282ecbed1ca9eb17de4cb1b6e326.jpg',\n                            '04fb4d719e9fe2b6ffe32d9ae7be8a22.jpg',\n                            '0e79be614f12deb4f7cae18614b7391b.jpg']]","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-03-13T07:48:33.885785Z","iopub.execute_input":"2025-03-13T07:48:33.886000Z","iopub.status.idle":"2025-03-13T07:48:33.889706Z","shell.execute_reply.started":"2025-03-13T07:48:33.885982Z","shell.execute_reply":"2025-03-13T07:48:33.888867Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_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)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T07:48:34.029651Z","iopub.execute_input":"2025-03-13T07:48:34.029889Z","iopub.status.idle":"2025-03-13T07:48:34.034073Z","shell.execute_reply.started":"2025-03-13T07:48:34.029868Z","shell.execute_reply":"2025-03-13T07:48:34.033342Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = ResNet50()\ntest_data = read_and_prep_images(img_paths)\npreds = model.predict(test_data)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T07:51:26.352969Z","iopub.execute_input":"2025-03-13T07:51:26.353285Z","iopub.status.idle":"2025-03-13T07:51:33.004491Z","shell.execute_reply.started":"2025-03-13T07:51:26.353240Z","shell.execute_reply":"2025-03-13T07:51:33.003756Z"}},"outputs":[],"execution_count":null},{"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, class_list_path='../input/resnet50/imagenet_class_index.json')\n\nfor i, img_path in enumerate(img_paths):\n    display(Image(img_path))\n    print(most_likely_labels[i])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T07:51:45.178084Z","iopub.execute_input":"2025-03-13T07:51:45.178433Z","iopub.status.idle":"2025-03-13T07:51:45.236523Z","shell.execute_reply.started":"2025-03-13T07:51:45.178407Z","shell.execute_reply":"2025-03-13T07:51:45.235697Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}