diff --git a/examples/video-yolov5-detection.ipynb b/examples/video-yolov5-detection.ipynb index 844a3ba0..fb267744 100644 --- a/examples/video-yolov5-detection.ipynb +++ b/examples/video-yolov5-detection.ipynb @@ -31,17 +31,17 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "1fb73f7e-1bd9-4e8e-b113-94a714abca73", "metadata": {}, "outputs": [], "source": [ - "!pip install fastdup gdown -Uq" + "!pip install fastdup kaggle -Uq" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "90d6aea7-f03e-4a9c-ba2c-dee490579304", "metadata": { "tags": [] @@ -57,10 +57,10 @@ { "data": { "text/plain": [ - "'1.25'" + "'1.30'" ] }, - "execution_count": 2, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -75,67 +75,44 @@ "id": "372a2c62-82aa-4b78-828c-95edf6b74c91", "metadata": {}, "source": [ - "## Download & Extract Dataset" + "## Download & Extract Dataset\n", + "\n", + "\n", + "Let's download the [Video Fight Detection Dataset](https://www.kaggle.com/datasets/naveenk903/movies-fight-detection-dataset) from Kaggle. The dataset consists of real life videos of fight and non-fight scenes meant for video classification task.\n", + "\n", + "You can download the dataset by manually by heading to the dataset [homepage](https://www.kaggle.com/datasets/naveenk903/movies-fight-detection-dataset) or using the [Kaggle API](https://github.com/Kaggle/kaggle-api). \n", + "\n", + "Let's use the Kaggle API to download the dataset:" ] }, { "cell_type": "code", - "execution_count": 3, - "id": "a9525826-b454-43e4-a359-969e44335861", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Downloading...\n", - "From (uriginal): https://drive.google.com/uc?id=1fzmOgmRu557aU4lEbzL7XCf78KntFCeQ\n", - "From (redirected): https://drive.google.com/uc?id=1fzmOgmRu557aU4lEbzL7XCf78KntFCeQ&confirm=t&uuid=3d1e9ae0-b405-404f-a0ed-9174b2401633\n", - "To: /media/dnth/Active-Projects/fastdup/examples/data.zip\n", - "100%|██████████████████████████████████████| 56.9M/56.9M [00:05<00:00, 10.5MB/s]\n" - ] - } - ], + "execution_count": null, + "id": "6022c79f", + "metadata": {}, + "outputs": [], + "source": [ + "!kaggle datasets download -d naveenk903/movies-fight-detection-dataset" + ] + }, + { + "cell_type": "markdown", + "id": "8233b1b7", + "metadata": {}, "source": [ - "!gdown --fuzzy https://drive.google.com/file/d/1fzmOgmRu557aU4lEbzL7XCf78KntFCeQ/view" + "Next, extract the .zip file into a folder named `data`." ] }, { "cell_type": "code", - "execution_count": 4, - "id": "02650635-fb41-47f5-bd5c-ea78e8c80b15", + "execution_count": null, + "id": "2e0674a5", "metadata": { - "tags": [] + "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Archive: data.zip\n", - " creating: data/\n", - " inflating: data/video_14.mp4 \n", - " inflating: data/video_13.mp4 \n", - " inflating: data/video_12.mp4 \n", - " inflating: data/video_9.mp4 \n", - " inflating: data/video_15.mp4 \n", - " inflating: data/video_10.mp4 \n", - " inflating: data/video_11.mp4 \n", - " inflating: data/video_8.mp4 \n", - " inflating: data/video_1.mp4 \n", - " inflating: data/video_2.mp4 \n", - " inflating: data/video_3.mp4 \n", - " inflating: data/video_4.mp4 \n", - " inflating: data/video_5.mp4 \n", - " inflating: data/video_6.mp4 \n", - " inflating: data/video_7.mp4 \n" - ] - } - ], + "outputs": [], "source": [ - "!unzip data.zip" + "!unzip -q movies-fight-detection-dataset.zip -d data" ] }, { @@ -147,39 +124,19 @@ "\n", "fastdup works on images. We must first turn the videos into frames of images.\n", "\n", - "We can use a one-liner fastdup utility function to turn all the videos in a folder into frames:" + "We can use a one-liner fastdup utility function to turn all the videos in a folder into frames. This should create a new folder called `frames` that has all the frames from the videos." ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "9258e5af-0802-476b-85ba-2423240a2771", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "FastDup Software, (C) copyright 2022 Dr. Amir Alush and Dr. Danny Bickson.\n", - "2023-07-12 16:11:02 [INFO] Going to loop over dir data\n", - "2023-07-12 16:11:02 [INFO] Found total 15 videos to run on, 15 train, 0 test, name list 15, counter 15 \n" - ] - }, - { - "data": { - "text/plain": [ - "0" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "fastdup.extract_video_frames(input_dir=\"data\", work_dir=\"frames\")" + "fastdup.extract_video_frames(input_dir=\"data/\", work_dir=\"frames/\")" ] }, { @@ -194,19 +151,35 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "id": "bd3bf19f-1322-46cc-bfc3-d8db50689367", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Warning: fastdup create() without work_dir argument, output is stored in a folder named work_dir in your current working path.\n" + ] + } + ], + "source": [ + "fd = fastdup.create(input_dir='frames/')" + ] + }, + { + "cell_type": "markdown", + "id": "3d1dfd32", + "metadata": {}, "source": [ - "fd = fastdup.create(input_dir='frames', work_dir='yolov5_detection_work_dir')" + "For demonstration we'll just run on `num_images=2000`, feel free to change its value or omitting it altogether to run it on the entire dataset." ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "id": "29fde366-db7d-4fff-a537-2ff589cddffd", "metadata": { "tags": [] @@ -216,40 +189,40 @@ "name": "stdout", "output_type": "stream", "text": [ - "Trying to download yolov5s model from https://github.com/itsnine/yolov5-onnxruntime/raw/master/models/yolov5s.onnx\n", "FastDup Software, (C) copyright 2022 Dr. Amir Alush and Dr. Danny Bickson.\n", - "2023-07-12 16:11:11 [INFO] Going to loop over dir frames\n", - "2023-07-12 16:11:11 [INFO] Found total 99 images to run on, 99 train, 0 test, name list 99, counter 99 \n", + "2023-07-24 15:37:16 [INFO] Going to loop over dir frames\n", + "2023-07-24 15:37:16 [INFO] Found total 4791 images to run on, 4791 train, 0 test, name list 4791, counter 4791 \n", "FastDup Software, (C) copyright 2022 Dr. Amir Alush and Dr. Danny Bickson.utes\n", - "2023-07-12 16:11:22 [INFO] Going to loop over dir /tmp/crops_input.csv\n", - "2023-07-12 16:11:22 [INFO] Found total 130 images to run on, 130 train, 0 test, name list 130, counter 130 \n", - "2023-07-12 16:11:23 [INFO] Found total 130 images to run onstimated: 0 Minutes\n", - "Finished histogram 0.156\n", - "Finished bucket sort 0.168\n", - "2023-07-12 16:11:23 [INFO] 10) Finished write_index() NN model\n", - "2023-07-12 16:11:23 [INFO] Stored nn model index file yolov5_detection_work_dir/nnf.index\n", - "2023-07-12 16:11:23 [INFO] Total time took 1016 ms\n", - "2023-07-12 16:11:23 [INFO] Found a total of 0 fully identical images (d>0.990), which are 0.00 %\n", - "2023-07-12 16:11:23 [INFO] Found a total of 6 nearly identical images(d>0.980), which are 2.31 %\n", - "2023-07-12 16:11:23 [INFO] Found a total of 65 above threshold images (d>0.900), which are 25.00 %\n", - "2023-07-12 16:11:23 [INFO] Found a total of 13 outlier images (d<0.050), which are 5.00 %\n", - "2023-07-12 16:11:23 [INFO] Min distance found 0.555 max distance 0.988\n", - "2023-07-12 16:11:23 [INFO] Running connected components for ccthreshold 0.960000 \n", + "2023-07-24 15:46:41 [INFO] Going to loop over dir /tmp/crops_input.csv\n", + "2023-07-24 15:46:41 [INFO] Found total 4908 images to run on, 4908 train, 0 test, name list 4908, counter 4908 \n", + "2023-07-24 15:46:54 [INFO] Found total 4908 images to run ontimated: 0 Minutes\n", + "Finished histogram 1.056\n", + "Finished bucket sort 1.071\n", + "2023-07-24 15:46:54 [INFO] 74) Finished write_index() NN model\n", + "2023-07-24 15:46:54 [INFO] Stored nn model index file work_dir/nnf.index\n", + "2023-07-24 15:46:54 [INFO] Total time took 13135 ms\n", + "2023-07-24 15:46:54 [INFO] Found a total of 154 fully identical images (d>0.990), which are 1.57 %\n", + "2023-07-24 15:46:54 [INFO] Found a total of 553 nearly identical images(d>0.980), which are 5.63 %\n", + "2023-07-24 15:46:54 [INFO] Found a total of 7904 above threshold images (d>0.900), which are 80.52 %\n", + "2023-07-24 15:46:54 [INFO] Found a total of 492 outlier images (d<0.050), which are 5.01 %\n", + "2023-07-24 15:46:54 [INFO] Min distance found 0.581 max distance 1.000\n", + "2023-07-24 15:46:54 [INFO] Running connected components for ccthreshold 0.960000 \n", ".0\n", " ########################################################################################\n", "\n", "Dataset Analysis Summary: \n", "\n", - " Dataset contains 130 images\n", - " Valid images are 100.00% (130) of the data, invalid are 0.00% (0) of the data\n", - " Similarity: 4.62% (6) belong to 2 similarity clusters (components).\n", - " 95.38% (124) images do not belong to any similarity cluster.\n", - " Largest cluster has 30 (23.08%) images.\n", + " Dataset contains 4908 images\n", + " Valid images are 100.00% (4,908) of the data, invalid are 0.00% (0) of the data\n", + " Similarity: 19.01% (933) belong to 28 similarity clusters (components).\n", + " 80.99% (3,975) images do not belong to any similarity cluster.\n", + " Largest cluster has 128 (2.61%) images.\n", " For a detailed analysis, use `.connected_components()`\n", "(similarity threshold used is 0.9, connected component threshold used is 0.96).\n", "\n", - " Outliers: 8.46% (11) of images are possible outliers, and fall in the bottom 5.00% of similarity values.\n", - " For a detailed list of outliers, use `.outliers()`.\n" + " Outliers: 6.58% (323) of images are possible outliers, and fall in the bottom 5.00% of similarity values.\n", + " For a detailed list of outliers, use `.outliers()`.\n", + "\n" ] }, { @@ -258,7 +231,7 @@ "0" ] }, - "execution_count": 7, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -279,9 +252,10 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "id": "c13076de-3cf2-428f-866f-24278b082c02", "metadata": { + "scrolled": false, "tags": [] }, "outputs": [ @@ -289,16 +263,22 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 37.14it/s]\n" + "100%|████████████| 20/20 [00:01<00:00, 17.59it/s]\n", + "/home/dnth/anaconda3/envs/fastdup/lib/python3.10/site-packages/fastdup/galleries.py:933: SettingWithCopyWarning: \n", + "A value is trying to be set on a copy of a slice from a DataFrame.\n", + "Try using .loc[row_indexer,col_indexer] = value instead\n", + "\n", + "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", + " top_components['label'] = top_components['label'].apply(lambda x: x[:MAX_IMAGES_IN_GRID])\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Finished OK. Components are stored as image files yolov5_detection_work_dir/galleries/components_[index].jpg\n", - "Stored components visual view in yolov5_detection_work_dir/galleries/components.html\n", - "Execution time in seconds 0.1\n" + "Finished OK. Components are stored as image files work_dir/galleries/components_[index].jpg\n", + "Stored components visual view in work_dir/galleries/components.html\n", + "Execution time in seconds 1.6\n" ] }, { @@ -815,7 +795,7 @@ "
| Info | \n", + "|
|---|---|
| component | \n", + "2233 | \n", + "
| num_images | \n", + "24 | \n", + "
| mean_distance | \n", + "0.9604 | \n", + "