dashingzombie commited on
Commit
5e0a271
·
verified ·
1 Parent(s): 73e9758

Upload folder using huggingface_hub

Browse files
Files changed (8) hide show
  1. .gitignore +211 -0
  2. README.md +26 -3
  3. args.yaml +106 -0
  4. data.yaml +7 -0
  5. inference.py +22 -0
  6. requiremnts.txt +4 -0
  7. split_train_val.py +88 -0
  8. train.py +7 -0
.gitignore ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+ *.pt
209
+ *.jpg`
210
+ runs/
211
+ data/
README.md CHANGED
@@ -1,3 +1,26 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: ultralytics
3
+ pipeline_tag: image-segmentation
4
+ tags:
5
+ - yolo
6
+ - yolo11
7
+ - ultralytics
8
+ - segmentation
9
+ - instance-segmentation
10
+ license: mit
11
+ ---
12
+
13
+ # YOLOv11-seg – Earthworm Body Mask
14
+
15
+ This repository hosts a **custom YOLOv11 segmentation model** trained with [Ultralytics](https://github.com/ultralytics/ultralytics).
16
+ The model detects and segments earthworm bodies in images.
17
+
18
+ ## Model Details
19
+ - **Architecture:** YOLOv11-seg (Ultralytics)
20
+ - **Framework:** PyTorch / Ultralytics
21
+ - **Task:** Instance segmentation
22
+ - **Classes:**
23
+ - `0: body_mask`
24
+
25
+ ## Weights
26
+ - `best.pt` (current checkpoint uploaded here)
args.yaml ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ task: segment
2
+ mode: train
3
+ model: yolo11l-seg.pt
4
+ data: data.yaml
5
+ epochs: 500
6
+ time: null
7
+ patience: 100
8
+ batch: 4
9
+ imgsz: 1024
10
+ save: true
11
+ save_period: -1
12
+ cache: false
13
+ device: null
14
+ workers: 8
15
+ project: null
16
+ name: train4
17
+ exist_ok: false
18
+ pretrained: true
19
+ optimizer: auto
20
+ verbose: true
21
+ seed: 0
22
+ deterministic: true
23
+ single_cls: false
24
+ rect: false
25
+ cos_lr: false
26
+ close_mosaic: 10
27
+ resume: false
28
+ amp: true
29
+ fraction: 1.0
30
+ profile: false
31
+ freeze: null
32
+ multi_scale: false
33
+ overlap_mask: true
34
+ mask_ratio: 4
35
+ dropout: 0.0
36
+ val: true
37
+ split: val
38
+ save_json: false
39
+ save_hybrid: false
40
+ conf: null
41
+ iou: 0.7
42
+ max_det: 300
43
+ half: false
44
+ dnn: false
45
+ plots: true
46
+ source: null
47
+ vid_stride: 1
48
+ stream_buffer: false
49
+ visualize: false
50
+ augment: false
51
+ agnostic_nms: false
52
+ classes: null
53
+ retina_masks: false
54
+ embed: null
55
+ show: false
56
+ save_frames: false
57
+ save_txt: false
58
+ save_conf: false
59
+ save_crop: false
60
+ show_labels: true
61
+ show_conf: true
62
+ show_boxes: true
63
+ line_width: null
64
+ format: torchscript
65
+ keras: false
66
+ optimize: false
67
+ int8: false
68
+ dynamic: false
69
+ simplify: true
70
+ opset: null
71
+ workspace: null
72
+ nms: false
73
+ lr0: 0.01
74
+ lrf: 0.01
75
+ momentum: 0.937
76
+ weight_decay: 0.0005
77
+ warmup_epochs: 3.0
78
+ warmup_momentum: 0.8
79
+ warmup_bias_lr: 0.1
80
+ box: 7.5
81
+ cls: 0.5
82
+ dfl: 1.5
83
+ pose: 12.0
84
+ kobj: 1.0
85
+ nbs: 64
86
+ hsv_h: 0.015
87
+ hsv_s: 0.7
88
+ hsv_v: 0.4
89
+ degrees: 0.0
90
+ translate: 0.1
91
+ scale: 0.5
92
+ shear: 0.0
93
+ perspective: 0.0
94
+ flipud: 0.0
95
+ fliplr: 0.5
96
+ bgr: 0.0
97
+ mosaic: 1.0
98
+ mixup: 0.0
99
+ copy_paste: 0.0
100
+ copy_paste_mode: flip
101
+ auto_augment: randaugment
102
+ erasing: 0.4
103
+ crop_fraction: 1.0
104
+ cfg: null
105
+ tracker: botsort.yaml
106
+ save_dir: runs/segment/train4
data.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ path: yolo_split # dataset root dir
2
+ train: images/train # train images (relative to 'path') 4 images
3
+ val: images/val # val images (relative to 'path') 4 images
4
+ test: # test images (optional)
5
+
6
+ names:
7
+ 0: body_mask
inference.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from ultralytics import YOLO
4
+ import glob
5
+ # Load your trained segmentation model
6
+ model = YOLO('runs/segment/train/weights/last.pt')
7
+ IN_DIR = "/home/quentin/repos/yolov11-segmentation_earth-worm/data/yolo_split/images/val"
8
+ # Predict on an image, replace with your image path or URL
9
+
10
+ files = sorted(glob.glob(f"{IN_DIR}/*.jpg"))
11
+ for f in files:
12
+
13
+ results = model(f)
14
+ # Save results, this includes saving masks
15
+ os.makedirs("results/", exist_ok=True)
16
+ results[0].save(f"results/result_{os.path.basename(f)}")
17
+ #
18
+ # for f in sorted(glob.glob(f"{IN_DIR}/2024-10-08/*.jpg")):
19
+ # results = model(f)
20
+ # # Save results, this includes saving masks
21
+ # os.makedirs("results/2024-10-08", exist_ok=True)
22
+ # results[0].save(f"results/2024-10-08/result_{os.path.basename(f)}")
requiremnts.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ultralytics>=8.3
2
+ torch
3
+ torchvision
4
+ pillow
split_train_val.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import sys
3
+ import hashlib
4
+ import shutil
5
+ from pathlib import Path
6
+ from wsgiref.validate import assert_
7
+
8
+ from ultralytics.data.converter import convert_coco
9
+ import os
10
+
11
+
12
+ INPUT_DIR = "data/coco"
13
+ YOLO_DATA_DIR = "data/yolo"
14
+ TARGET_DIR = "data/yolo_split"
15
+
16
+
17
+
18
+ def md5_of_file(path, chunk=1<<20):
19
+ h = hashlib.md5()
20
+ with open(path, "rb") as f:
21
+ while True:
22
+ b = f.read(chunk)
23
+ if not b:
24
+ break
25
+ h.update(b)
26
+ return h.hexdigest()
27
+
28
+
29
+ if __name__ == "__main__":
30
+ if os.path.isdir(YOLO_DATA_DIR):
31
+ shutil.rmtree(YOLO_DATA_DIR)
32
+
33
+ if os.path.isdir(TARGET_DIR):
34
+ shutil.rmtree(TARGET_DIR)
35
+
36
+
37
+ convert_coco(labels_dir="data/coco", use_segments=True, save_dir=YOLO_DATA_DIR )
38
+
39
+ train_dir = os.path.join(TARGET_DIR,"images", "train")
40
+ train_dir_annotations = os.path.join(TARGET_DIR,"labels", "train")
41
+ val_dir = os.path.join(TARGET_DIR, "images","val")
42
+ val_dir_annotations = os.path.join(TARGET_DIR, "labels","val")
43
+
44
+ os.makedirs(train_dir, exist_ok=True)
45
+ os.makedirs(train_dir_annotations, exist_ok=True)
46
+ os.makedirs(val_dir, exist_ok=True)
47
+ os.makedirs(val_dir_annotations, exist_ok=True)
48
+
49
+ files = list(Path(INPUT_DIR).rglob("*.jpg"))
50
+ print(f"Found {len(files)} .jpg files")
51
+
52
+ n_train = n_val = 0
53
+ label_dir = os.path.join(YOLO_DATA_DIR, "labels", "default")
54
+
55
+ for f in files:
56
+ md5 = md5_of_file(f)
57
+ bucket = int(md5, 16) % 100
58
+ # label_file = os.path.join(label_dir, os.path.splitext(f.name)[0]) + ".txt")
59
+ label_basename = os.path.splitext(f.name)[0] + ".txt"
60
+ label_file = os.path.join(label_dir, label_basename)
61
+ if not os.path.exists(label_file):
62
+ continue
63
+
64
+ if bucket < 20:
65
+ dst = os.path.join(val_dir, f.name)
66
+ shutil.copy2(f, dst)
67
+ dst = os.path.join(val_dir_annotations, label_basename)
68
+ n_val += 1
69
+ else:
70
+ dst = os.path.join(train_dir, f.name)
71
+ shutil.copy2(f, dst)
72
+ dst = os.path.join(train_dir_annotations, label_basename)
73
+ n_train += 1
74
+
75
+ lines = []
76
+ with open(label_file, "r", encoding="utf-8") as f:
77
+ for line in f:
78
+ parts = line.strip().split()
79
+ if not parts:
80
+ continue
81
+ if parts[0] == "1":
82
+ parts[0] = "0"
83
+ lines.append(" ".join(parts))
84
+
85
+ with open(dst, "w", encoding="utf-8") as f:
86
+ f.write("\n".join(lines))
87
+
88
+ print(f"Copied {n_train} files to train/, {n_val} files to val/")
train.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from ultralytics import YOLO
2
+
3
+ # Load a model
4
+ model = YOLO("yolo11l-seg.pt") # load a pretrained model (recommended for training)
5
+
6
+ # Train the model
7
+ results = model.train(data="data.yaml", epochs=500, imgsz=1024, batch=4)