{"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 imagededup","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-07-22T05:32:15.175659Z","iopub.execute_input":"2023-07-22T05:32:15.176299Z","iopub.status.idle":"2023-07-22T05:32:28.679707Z","shell.execute_reply.started":"2023-07-22T05:32:15.176261Z","shell.execute_reply":"2023-07-22T05:32:28.677976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.simplefilter('ignore')\nwarnings.filterwarnings('ignore', module='imagededup')\n\n\nfrom imagededup.methods import CNN, PHash\nfrom multiprocessing import cpu_count\n\nnum_cpus = cpu_count()\nprint(\"Number of CPUs:\", num_cpus)\n\n\nimage_dir = \"/kaggle/input/contrail-png-image-mask/contrail\"","metadata":{"execution":{"iopub.status.busy":"2023-07-22T05:32:28.682773Z","iopub.execute_input":"2023-07-22T05:32:28.683293Z","iopub.status.idle":"2023-07-22T05:32:32.965396Z","shell.execute_reply.started":"2023-07-22T05:32:28.68324Z","shell.execute_reply":"2023-07-22T05:32:32.964376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# NOTE: There will be cases where\n# {'1.png': ('2.png', 0.96),\n#  '2.png': ('1.png', 0.96)}","metadata":{"execution":{"iopub.status.busy":"2023-07-22T05:32:32.966524Z","iopub.execute_input":"2023-07-22T05:32:32.967244Z","iopub.status.idle":"2023-07-22T05:32:32.971683Z","shell.execute_reply.started":"2023-07-22T05:32:32.967208Z","shell.execute_reply":"2023-07-22T05:32:32.970885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# PHash","metadata":{}},{"cell_type":"code","source":"phash = PHash()\nencode = phash.encode_images(image_dir=image_dir)","metadata":{"execution":{"iopub.status.busy":"2023-07-22T05:32:32.975073Z","iopub.execute_input":"2023-07-22T05:32:32.975602Z","iopub.status.idle":"2023-07-22T05:33:53.340798Z","shell.execute_reply.started":"2023-07-22T05:32:32.975559Z","shell.execute_reply":"2023-07-22T05:33:53.3396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# max_distance_threshold (0-64) default 10\nduplicates = phash.find_duplicates(\n    encoding_map=encode,\n    scores=True,\n    max_distance_threshold=6,\n    outfile='duplicates.json'\n)","metadata":{"execution":{"iopub.status.busy":"2023-07-22T05:33:53.342447Z","iopub.execute_input":"2023-07-22T05:33:53.342807Z","iopub.status.idle":"2023-07-22T05:36:19.074702Z","shell.execute_reply.started":"2023-07-22T05:33:53.342771Z","shell.execute_reply":"2023-07-22T05:36:19.073466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, (img, curr_duplicates) in enumerate(duplicates.items()):\n    print(img, curr_duplicates)\n    if i == 15: break","metadata":{"execution":{"iopub.status.busy":"2023-07-22T05:36:26.862526Z","iopub.execute_input":"2023-07-22T05:36:26.862956Z","iopub.status.idle":"2023-07-22T05:36:26.8696Z","shell.execute_reply.started":"2023-07-22T05:36:26.862921Z","shell.execute_reply":"2023-07-22T05:36:26.868407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 9:45pm","metadata":{"execution":{"iopub.status.busy":"2023-07-22T05:36:19.084826Z","iopub.execute_input":"2023-07-22T05:36:19.085247Z","iopub.status.idle":"2023-07-22T05:36:19.097806Z","shell.execute_reply.started":"2023-07-22T05:36:19.085206Z","shell.execute_reply":"2023-07-22T05:36:19.096467Z"},"trusted":true},"execution_count":null,"outputs":[]}]}