A detection script that saves every run to the same folder eventually costs you results. Annotated images get overwritten, labels from one batch mix with another, and nobody can say afterwards which files belonged to which shift. This guide is for engineers who launch inference from Python or a shell on a shop-floor vision system and need each run to write to its own, clearly named directory.
By the end you will know how to pass the output path correctly, how to name folders so they sort and audit well, and how to verify the fix before the first production batch runs.
Why results land in the default folder
Most detection scripts define a default output directory, often named exp, and create numbered copies (exp2, exp3) when it already exists. Two things go wrong in practice:
- The script receives the name argument but its parser ignores or overwrites it, so the default is used.
- Only the name is passed and the project path is left at its default, so the run writes somewhere unexpected and the operator never sees the files.
The reliable habit is to control the full path yourself and never depend on the script's fallback numbering. Pass both the project root and the run name, and check the parsed values at the start of every run:
import subprocess, argparse
args = [
"python3", "detect.py",
"--weights", "/models/best.pt",
"--img", "416",
"--conf", "0.4",
"--source", "/images/inbound/",
"--project", "/data/results/line1",
"--name", run_name, # e.g. 2025-06-12_14-30-05_partA
"--save-txt",
]
result = subprocess.run(args, capture_output=True, text=True)
print(result.stdout[-2000:]) # confirm the parsed project and name
If the printed values are wrong, the argument list itself is wrong, not the folder logic. Print the list before the call; a missing element or a swapped value explains most cases where the argument seems to be ignored.
Build the run name from data, not by hand
A name a human types at 6 a.m. is the name that collides at 6 p.m. Generate it from the things that identify the run: time, station and part or batch:
Use a timestamp in year-month-day then hour-minute-second order. That format sorts chronologically as plain text, which means the newest run is always the last entry in a directory listing, and scripts can find it without reading file dates.
Avoid spaces, uppercase collisions and locale-dependent date styles. 2025-06-12_14-30-05_partA works everywhere; June 12 results (2) does not.
One folder per run, grouped by station
A layout that holds up on a real line:
/data/results/
line1/
2025-06-12_06-15-00_stationA_batch4412/
images/
labels/
run_meta.txt
2025-06-12_09-40-22_stationA_batch4413/
Write a small run_meta.txt in each folder with the model file, its hash or version, the confidence threshold, camera exposure and the trigger count. Six lines of metadata turn a folder of images into a reproducible experiment. When you later compare a good batch against a bad one, the threshold and model version are the first two questions anyone asks.
Verify the fix before production
- Run once with a known name and confirm the folder appears exactly where the project path points.
- Run a second time with the same name. Decide and enforce the behaviour: either the script must fail loudly, or it must append a counter you log. Silent overwrites are never acceptable.
- Check that image, label and metadata files all landed inside the run folder, not in the project root beside it.
- Fill the disk in a test to a realistic level and confirm the script's error handling writes a clear message rather than losing the batch.
Hardware that keeps up with continuous result writing
Writing annotated images continuously needs disk headroom and enough LAN ports for the cameras feeding the detector. A vision controller can combine camera connectivity and result storage; check sustained write performance against your actual workload.
The MV-VC3301H-128G66 pairs an Intel Core i3 with 8 GB of memory and a 128 GB SSD, includes 4 built-in light channels and carries a bundled vision software license.
- LAN ports
- 5+ LAN ports
- USB 3 ports
- 3-4 USB 3 ports
- Light outputs
- 4 built-in channels
- Memory
- 8 GB
The MV-VC5525-256G70-NN offers a 12th-generation Intel Core i5, 32 GB of memory and 8 built-in light channels, with PoE camera ports for compatible cameras. For multi-camera stations or long retention periods, verify processing throughput and usable storage separately.
- LAN ports
- 5+ LAN ports
- USB 3 ports
- 3-4 USB 3 ports
- PoE
- PoE camera ports
- Light outputs
- 8 built-in channels
If the inspection itself runs on the device, check whether a smart camera can export compact pass/fail records, full image sets or both. The same folder discipline applies to exported files: one directory per shift or batch, metadata included. The camera finder filters by interface, resolution and shutter type; browse the vision controller category for controller options, or start from the system configurator.
Disk hygiene: retention, archiving, alarms
Estimate storage before you tune the model. Suppose a station inspects 2 parts per minute over an 8-hour shift, saving one annotated image at roughly 300 KB plus a small label file:
That is manageable, but add a second camera or save raw images too and it multiplies fast. Set a retention rule (for example, keep 30 days of runs, archive flagged failures indefinitely) and run the cleanup from the same scheduler that starts the inference. Alarm when free disk drops below a threshold; a full disk mid-shift silently stops result saving before anyone notices.
When the usual answer is wrong
- Retraining to change output paths is wasted effort. Folder logic lives in the launcher script, not the model. Fix the arguments.
- Numbered fallback folders (exp, exp2, exp3) are not a naming scheme. They hide which run was which and break every script that expects a fixed path.
- Cloud or network shares are not automatically safer. A network hiccup during write can truncate a result file; write locally, then sync, so a failed sync never destroys the original.
Pre-flight checklist
- Project and name arguments both passed, values printed at run start
- Timestamp-ordered run names, no spaces or special characters
- One folder per run, grouped by station, with a metadata file inside
- Overwrite behaviour decided: fail loudly or logged counter, never silent
- Storage estimate done, retention and cleanup scheduled, low-disk alarm set
Quick reference
- Pass
--projectand--nametogether; the run writes to their combination. - Name runs
YYYY-MM-DD_HH-MM-SS_station_partID. - Write metadata next to the images: model version, threshold, exposure.
- Verify with two test runs and a disk-fill test before the first batch.
- Estimate storage: images per shift × size per image, then double it.
For training-stage folder problems, see anomaly detection custom dataset training: fix folder and mask errors. For a related image-storage workflow, see barcode inspection image archiving to cloud storage. If several frames can be in flight, asynchronous vision result frame matching with timestamps addresses the association between each image and its result.
Ready to spec the machine that runs it? Start at the vision controllers category or use the light controller step if illumination comes next, and contact us for help sizing storage to your line.
Questions
Why does my script still write results to the default exp folder?
Most detection scripts fall back to the default name when the name argument is not parsed or is placed after a flag the parser does not expect. Print the parsed argument object at the start of the run, check that the argument list actually contains the name and its value, and pass both project and name so the full path is defined. If the value is still wrong, the argument is likely being consumed or reordered before parsing.
Should each inspection run get its own folder or append to one folder?
Give each run its own folder when results must stay traceable to a time, part or batch. Append to one folder only for continuous monitoring where you already log everything elsewhere and disk space is tight. Separate folders make cleanup, audit and re-inspection far simpler, and they stop one bad run from overwriting annotated images of another.
What is a good folder naming scheme for vision results?
Use project, line or station, then a timestamp in year-month-day hour-minute-second order, then an optional part or batch ID, for example runs/line1/2025-06-12_14-30-05_partA. That order sorts chronologically by name, survives lowercase file systems because it has no spaces or special characters, and lets scripts find the newest run by sorting the directory listing.
How much storage do saved inference images and labels need?
Multiply images per run by file size per image, including annotated copies and label text files. A run saving 500 images at roughly 300 KB each plus annotated versions needs on the order of 300 MB. Estimate your runs per shift, set a retention limit, and archive or delete old runs automatically so the disk never fills during production.

