<jupyter_start><jupyter_text>Litter Detection in Glasgow City using YOLOv5This notebook applies the chosen developed object detection model to the 50 street view images per data zone data set. Please read `docs/DATA.md` and download images in which to detect within. Configuration You may wish to change these:<jupyter_code># The location of the images to use as litter detection input.
images = "../../data/images" # try "../../data/example-images-to-run-detection"

# The directory in which to put the detection results.
destination = "../../runs/detect" # The directory in which to put the results directory.

# 80% confidence threshold for detection.
confidence_threshold = 0.8

# The thickness of the line to draw around detected litter.
line_thickness = 3<jupyter_output><empty_output><jupyter_text>You likely do not want to change these:<jupyter_code>name = "mosaic-noise-x3-tuned-0.8" # The name of the directory in which to put the results.
model = "mosaic-noise-x3-tuned" # The name of the chosen model.
weights = f"weights/chosen-model.pt" # The weights of the model.
images_per_data_zone = 50 # We are detecting on 50 images per data zone.
source = f"{images}/../images-expanded" # The directory that contains all the street view images.<jupyter_output><empty_output><jupyter_text>_Optional:_ Create the source directory that contains all of the images to run inference on.This is utility code used to create the right directory/file structure.<jupyter_code>import glob
import shutil
import os
import filecmp
from pathlib import Path

remove_dups = False

if not os.path.isdir(source):
    os.makedirs(source)
    for entry in os.listdir(images):
        entry_path = Path(f"{images}/{entry}")
        if os.path.isdir(entry_path):
            files = glob.iglob(f"{images}/{entry}/*.jpg", recursive=True)
            for f in list(files)[:images_per_data_zone]:
                dup = False
                if remove_dups:
                    for g in os.listdir(source):
                        if filecmp.cmp(f, os.path.join(source, g), shallow=False):
                            dup = True
                            break
                if not dup:
                    shutil.copy(f, source)<jupyter_output><empty_output><jupyter_text>Inference<jupyter_code>%%time
!python yolov5/detect.py --weights $weights --source $source --project $destination --name $name --conf $confidence_threshold --line-thickness $line_thickness --save-txt --save-conf --hide-labels<jupyter_output>CPU times: total: 15.6 ms
Wall time: 6.58 s
{'fraction_non_alphanumeric': 0.09653270291568164, 'fraction_numerical': 0.009062253743104806, 'mean_word_length': 3.2176079734219267, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '650449', 'license': 'MIT', 'n_tokens_mistral': 763, 'n_tokens_neox': 729, 'n_words': 256, 'path': 'models/yolov5/detect.ipynb', 'repo_name': 'Garee/glasgow-litter-mirror', 'size': '2538'}