{"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":"# Fastdup tuturial - using keamns algorithm","metadata":{"execution":{"iopub.status.busy":"2022-09-20T13:13:26.900865Z","iopub.execute_input":"2022-09-20T13:13:26.902443Z","iopub.status.idle":"2022-09-20T13:13:26.934353Z","shell.execute_reply.started":"2022-09-20T13:13:26.902307Z","shell.execute_reply":"2022-09-20T13:13:26.933149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Fastdup tutorial, clustering similar images using kmeans vs. connected components algorithm","metadata":{}},{"cell_type":"code","source":"%pip install fastdup","metadata":{"execution":{"iopub.status.busy":"2022-09-20T13:13:27.114366Z","iopub.execute_input":"2022-09-20T13:13:27.114998Z","iopub.status.idle":"2022-09-20T13:13:43.088697Z","shell.execute_reply.started":"2022-09-20T13:13:27.114959Z","shell.execute_reply":"2022-09-20T13:13:43.087611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls /kaggle/input/leaf-classification/","metadata":{"execution":{"iopub.status.busy":"2022-09-20T13:13:43.093849Z","iopub.execute_input":"2022-09-20T13:13:43.094208Z","iopub.status.idle":"2022-09-20T13:13:44.192528Z","shell.execute_reply.started":"2022-09-20T13:13:43.094163Z","shell.execute_reply":"2022-09-20T13:13:44.190924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!unzip -qq '/kaggle/input/leaf-classification/images.zip' -d images","metadata":{"execution":{"iopub.status.busy":"2022-09-20T13:13:44.195368Z","iopub.execute_input":"2022-09-20T13:13:44.195777Z","iopub.status.idle":"2022-09-20T13:13:46.161074Z","shell.execute_reply.started":"2022-09-20T13:13:44.195735Z","shell.execute_reply":"2022-09-20T13:13:46.159454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import fastdup\n!rm -fr out\nfastdup.run_kmeans('images/images',work_dir='out',num_clusters=100)","metadata":{"execution":{"iopub.status.busy":"2022-09-20T13:14:46.570714Z","iopub.execute_input":"2022-09-20T13:14:46.572064Z","iopub.status.idle":"2022-09-20T13:15:04.696316Z","shell.execute_reply.started":"2022-09-20T13:14:46.572020Z","shell.execute_reply":"2022-09-20T13:15:04.694939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Cluster images based on the KMeans algorithm","metadata":{}},{"cell_type":"code","source":"from IPython.display import HTML\nfastdup.create_kmeans_clusters_gallery('out', save_path='.',max_width=250)\n","metadata":{"execution":{"iopub.status.busy":"2022-09-20T13:15:13.957936Z","iopub.execute_input":"2022-09-20T13:15:13.958585Z","iopub.status.idle":"2022-09-20T13:15:21.931956Z","shell.execute_reply.started":"2022-09-20T13:15:13.958530Z","shell.execute_reply":"2022-09-20T13:15:21.930704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"HTML('./components.html')","metadata":{"execution":{"iopub.status.busy":"2022-09-20T13:15:25.117752Z","iopub.execute_input":"2022-09-20T13:15:25.118290Z","iopub.status.idle":"2022-09-20T13:15:25.262794Z","shell.execute_reply.started":"2022-09-20T13:15:25.118245Z","shell.execute_reply":"2022-09-20T13:15:25.260002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Now cluster images based on connected components algorithm","metadata":{}},{"cell_type":"code","source":"fastdup.run('images/images', run_mode=2, work_dir='out')\nfastdup.create_components_gallery('out',save_path='.')","metadata":{"execution":{"iopub.status.busy":"2022-09-20T13:14:17.688045Z","iopub.execute_input":"2022-09-20T13:14:17.688435Z","iopub.status.idle":"2022-09-20T13:14:24.670978Z","shell.execute_reply.started":"2022-09-20T13:14:17.688403Z","shell.execute_reply":"2022-09-20T13:14:24.669924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"HTML('./components.html')","metadata":{"execution":{"iopub.status.busy":"2022-09-20T13:14:24.672522Z","iopub.execute_input":"2022-09-20T13:14:24.673127Z","iopub.status.idle":"2022-09-20T13:14:24.750933Z","shell.execute_reply.started":"2022-09-20T13:14:24.673068Z","shell.execute_reply":"2022-09-20T13:14:24.749264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}