{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":6799,"databundleVersionId":4225553,"sourceType":"competition"},{"sourceId":7759928,"sourceType":"datasetVersion","datasetId":4538146}],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport tensorflow as tf\nimport matplotlib.pyplot as plt\nfrom PIL import Image\nimport os, shutil\nimport zipfile","metadata":{"execution":{"iopub.status.busy":"2024-03-07T12:53:50.145242Z","iopub.execute_input":"2024-03-07T12:53:50.145688Z","iopub.status.idle":"2024-03-07T12:54:06.795625Z","shell.execute_reply.started":"2024-03-07T12:53:50.145653Z","shell.execute_reply":"2024-03-07T12:54:06.794266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!wget -O images.zip http://images.cocodataset.org/zips/val2017.zip","metadata":{"execution":{"iopub.status.busy":"2024-03-07T12:54:08.86321Z","iopub.execute_input":"2024-03-07T12:54:08.86396Z","iopub.status.idle":"2024-03-07T12:54:24.434692Z","shell.execute_reply.started":"2024-03-07T12:54:08.863921Z","shell.execute_reply":"2024-03-07T12:54:24.433354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with zipfile.ZipFile(\"images.zip\", \"r\") as zip_ref:\n  zip_ref.extractall(\"CocoImages\")","metadata":{"execution":{"iopub.status.busy":"2024-03-07T12:54:26.499918Z","iopub.execute_input":"2024-03-07T12:54:26.500419Z","iopub.status.idle":"2024-03-07T12:54:28.871575Z","shell.execute_reply.started":"2024-03-07T12:54:26.500373Z","shell.execute_reply":"2024-03-07T12:54:28.87016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.rmtree(\"Color\")\nshutil.rmtree(\"Grey\")","metadata":{"execution":{"iopub.status.busy":"2024-03-07T12:55:59.426176Z","iopub.execute_input":"2024-03-07T12:55:59.4268Z","iopub.status.idle":"2024-03-07T12:55:59.433399Z","shell.execute_reply.started":"2024-03-07T12:55:59.426761Z","shell.execute_reply":"2024-03-07T12:55:59.431989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cocopath = \"CocoImages/val2017\"\ncocofiles = os.listdir(cocopath)\nos.makedirs(\"Color\")\nos.makedirs(\"Grey\")\nnp.random.shuffle(cocofiles)\nidx = 0\nsx, sy = [],[]\nfor f in cocofiles:\n    img = np.array(Image.open(os.path.join(cocopath, f)))\n    if len(img.shape) != 3 or img.shape[0] != 640 or img.shape[1] !=640:\n        continue\n    sx.append(img.shape[0])\n    sy.append(img.shape[1])\n    shutil.copy(os.path.join(cocopath,f), os.path.join(\"Color\",str(idx)+\".jpg\"))\n    img = np.sum(img, axis=2)/3.0\n    image_pil = Image.fromarray(np.uint8(img))  # Convert to uint8 data type if necessary\n    image_pil.save(os.path.join(\"Grey\",str(idx)+\".jpg\"))\n    print(idx)\n    idx+=1\n    if(idx>=100):\n        break","metadata":{"execution":{"iopub.status.busy":"2024-03-07T12:56:00.360845Z","iopub.execute_input":"2024-03-07T12:56:00.3613Z","iopub.status.idle":"2024-03-07T12:56:25.864707Z","shell.execute_reply.started":"2024-03-07T12:56:00.361267Z","shell.execute_reply":"2024-03-07T12:56:25.863403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with zipfile.ZipFile(\"Color.zip\", 'w') as zipf:\n    # Walk through all the files and directories in the directory_to_zip\n    for foldername, subfolders, filenames in os.walk(\"Color\"):\n        for filename in filenames:\n            # Create the full path to the file\n            file_path = os.path.join(foldername, filename)\n            # Add the file to the zip file\n            zipf.write(file_path, os.path.relpath(file_path, \"Color\"))\n            \nwith zipfile.ZipFile(\"Grey.zip\", 'w') as zipf:\n    # Walk through all the files and directories in the directory_to_zip\n    for foldername, subfolders, filenames in os.walk(\"Grey\"):\n        for filename in filenames:\n            # Create the full path to the file\n            file_path = os.path.join(foldername, filename)\n            # Add the file to the zip file\n            zipf.write(file_path, os.path.relpath(file_path, \"Grey\"))","metadata":{"execution":{"iopub.status.busy":"2024-03-07T12:56:41.616029Z","iopub.execute_input":"2024-03-07T12:56:41.6165Z","iopub.status.idle":"2024-03-07T12:56:41.699139Z","shell.execute_reply.started":"2024-03-07T12:56:41.616466Z","shell.execute_reply":"2024-03-07T12:56:41.697702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}