Skip to content

Commit a8aa4e8

Browse files
authored
Fix api docker (#10)
* bump: update tree-disk-pith version to 0.1.5 * refactor: move directory creation and model downloads to main execution context * refactor: remove unused method parameter from detect_pith function * feat: add checks to skip model download if already exists * chore: update .dockerignore to exclude environment files * feat: add volume mappings for models, input, and output directories in compose.yml * refactor: remove root_dir argument and related validations from CLI and config * refactor: convert output_dir to string and update EndPoints reference in postprocessing * docs: remove root directory option from README * feat: support platform-specific devernay binaries for Linux and macOS * refactor: disable debug mode in test cases for treediskrings
1 parent 3cbd082 commit a8aa4e8

File tree

18 files changed

+171
-146
lines changed

18 files changed

+171
-146
lines changed

compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ services:
88
- ./tree-disk-api/.env.production.local
99
ports:
1010
- 3001:3100
11+
volumes:
12+
- ./tree-disk-api/models:/app/models
13+
- ./tree-disk-api/input:/app/input
14+
- ./tree-disk-api/output:/app/output

tree-disk-api/.dockerignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ docker.compose.yml
3333
output/
3434
input/
3535
tests/
36-
models/
36+
models/
37+
38+
# env
39+
.env
40+
.env.*

tree-disk-api/poetry.lock

Lines changed: 97 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tree-disk-api/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ uvicorn = "^0.32.0"
1414
gunicorn = "^23.0.0"
1515
python-multipart = "^0.0.17"
1616
tree-disk-segmentation = "^0.1.3"
17-
tree-disk-pith = "^0.1.4"
17+
tree-disk-pith = "^0.1.5"
1818
tree-disk-rings = "^0.4.7"
1919
gdown = "^5.2.0"
2020
python-dotenv = "^1.0.1"

tree-disk-api/src/api/endpoints/pith.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ async def detect_pith(
4343
input_image=path,
4444
model_path=YOLO_MODEL_PATH,
4545
output_dir=OUTPUT_DIR,
46-
method="apd_dl",
4746
save_results=SAVE_RESULTS,
4847
debug=DEBUG,
4948
)

tree-disk-api/src/config/preparation.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def download_u2net_model():
1515
"""
1616
Download the model from Google Drive.
1717
"""
18+
if U2NET_MODEL_PATH.exists():
19+
logger.info(
20+
f"U2NET model already exists at {U2NET_MODEL_PATH}, skipping download."
21+
)
22+
return
23+
1824
file_id = "10HXfiEMT4QapiRXMSSEJEAViRmRmSDUW"
1925
url = f"https://drive.google.com/uc?id={file_id}"
2026

@@ -27,6 +33,12 @@ def download_yolo_model():
2733
"""
2834
Download the model from Google Drive.
2935
"""
36+
if YOLO_MODEL_PATH.exists():
37+
logger.info(
38+
f"YOLO model already exists at {YOLO_MODEL_PATH}, skipping download."
39+
)
40+
return
41+
3042
file_id = "1_-dDH4DNiL8wbgiPWPaNqne7kbJyZc8z"
3143
url = f"https://drive.google.com/uc?id={file_id}"
3244

@@ -44,6 +56,8 @@ def create_dirs():
4456
MODEL_PATH.mkdir(parents=True, exist_ok=True)
4557

4658

47-
create_dirs()
48-
download_u2net_model()
49-
download_yolo_model()
59+
if __name__ == "__main__":
60+
# When running this file directly, create dirs and download models.
61+
create_dirs()
62+
download_u2net_model()
63+
download_yolo_model()

tree-disk-api/src/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import uvicorn
66
import logging
77

8+
from .config.preparation import create_dirs
89
from .config.settings import DEBUG, log_settings
910
from .api.router import router
1011

@@ -22,6 +23,8 @@ async def lifespan(app: FastAPI):
2223
# print all settings in debug
2324
log_settings()
2425

26+
create_dirs()
27+
2528
yield
2629

2730

tree-disk-rings/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ tree-disk-rings \
7171
| `--cx` | int | Yes | - | Pith x-coordinate |
7272
| `--cy` | int | Yes | - | Pith y-coordinate |
7373
| `--output_dir` | str | No | `./output` | Output directory path |
74-
| `--root` | str | No | Current dir | Root directory of the repository |
7574
| `--sigma` | float | No | 3.0 | Gaussian kernel parameter for edge detection |
7675
| `--th_low` | float | No | 5.0 | Low threshold for gradient magnitude |
7776
| `--th_high` | float | No | 20.0 | High threshold for gradient magnitude |
@@ -105,5 +104,5 @@ pytest
105104

106105
3. Compile the external C code:
107106
```bash
108-
cd ./externas/devernay_1.0 && make clean && make
107+
cd ./externals/devernay_1.0 && make clean && make
109108
```

tree-disk-rings/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "tree-disk-rings"
3-
version = "0.4.7"
3+
version = "0.4.8"
44
description = "A package for tree disk rings detection in images"
55
authors = ["Tony <[email protected]>"]
66
license = "MIT"
@@ -11,7 +11,8 @@ keywords = ["tree", "rings", "image processing"]
1111
packages = [{ include = "treediskrings", from = "src" }]
1212

1313
include = [
14-
"src/treediskrings/externals/devernay.out",
14+
"src/treediskrings/externals/linux/devernay.out",
15+
"src/treediskrings/externals/macos/devernay.out",
1516
]
1617

1718
[tool.poetry.dependencies]

tree-disk-rings/src/treediskrings/cli.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ def parse_arguments() -> argparse.Namespace:
2525
parser.add_argument(
2626
"--output_dir", default="./output", help="Output directory", metavar="DIR"
2727
)
28-
parser.add_argument(
29-
"--root_dir",
30-
default="./",
31-
help="Root directory of the repository",
32-
metavar="DIR",
33-
)
3428
parser.add_argument(
3529
"--sigma",
3630
type=float,
@@ -106,7 +100,6 @@ def main():
106100
# Configure settings from CLI arguments
107101
configure(
108102
input_image=args.input_image,
109-
root_dir=args.root_dir,
110103
output_dir=args.output_dir,
111104
cx=args.cx,
112105
cy=args.cy,

0 commit comments

Comments
 (0)