{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install git+https://github.com/yu4u/seam-carving.git","metadata":{"execution":{"iopub.status.busy":"2023-06-03T05:25:13.04583Z","iopub.execute_input":"2023-06-03T05:25:13.046513Z","iopub.status.idle":"2023-06-03T05:25:32.143238Z","shell.execute_reply.started":"2023-06-03T05:25:13.046466Z","shell.execute_reply":"2023-06-03T05:25:32.141826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport numpy as np\nfrom pathlib import Path\nfrom PIL import Image\nImage.MAX_IMAGE_PIXELS = None\nimport matplotlib.pyplot as plt\nimport seam_carving\nfrom concurrent.futures import ThreadPoolExecutor\nseam_carving.carve.MAX_MEAN_ENERGY = 2.0","metadata":{"execution":{"iopub.status.busy":"2023-06-03T05:25:32.145803Z","iopub.execute_input":"2023-06-03T05:25:32.146208Z","iopub.status.idle":"2023-06-03T05:25:32.311981Z","shell.execute_reply.started":"2023-06-03T05:25:32.146174Z","shell.execute_reply":"2023-06-03T05:25:32.31088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs(\"./test\", exist_ok=True)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T05:25:32.313356Z","iopub.execute_input":"2023-06-03T05:25:32.313867Z","iopub.status.idle":"2023-06-03T05:25:32.317828Z","shell.execute_reply.started":"2023-06-03T05:25:32.313838Z","shell.execute_reply":"2023-06-03T05:25:32.31703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def process_image(img_path):\n    all_exists = os.listdir(\"/kaggle/input/sc-test-data/test\")\n    if img_path.stem+\".jpg\" not in all_exists:\n        img = Image.open(img_path)\n        img = seam_carving.resize(img, (100, 100), energy_mode='backward', order='width-first')\n        img = Image.fromarray(img)\n\n    else:\n        img_path = Path(f\"/kaggle/input/sc-test-data/test/{img_path.stem}.jpg\")\n        img = Image.open(img_path)\n        \n\n    img.save(f'./test/{img_path.stem}.jpg')\n        \ndef run():\n    image_paths = sorted(Path(\"/kaggle/input/extracting-attributes-from-fashion-images-2/test/\").glob(\"*\"))\n\n    with ThreadPoolExecutor(max_workers=4) as executor:\n        executor.map(process_image, image_paths)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T16:43:28.900814Z","iopub.execute_input":"2023-06-02T16:43:28.901255Z","iopub.status.idle":"2023-06-02T16:43:28.916253Z","shell.execute_reply.started":"2023-06-02T16:43:28.901206Z","shell.execute_reply":"2023-06-02T16:43:28.915077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"run()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T16:43:28.917839Z","iopub.execute_input":"2023-06-02T16:43:28.918283Z","iopub.status.idle":"2023-06-02T16:43:29.93905Z","shell.execute_reply.started":"2023-06-02T16:43:28.918243Z","shell.execute_reply":"2023-06-02T16:43:29.936836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}