Spaces:
Sleeping
Sleeping
{{Your Name}}
commited on
Commit
·
2c4e7b0
0
Parent(s):
adding demo file
Browse files- .gitignore +52 -0
- README.md +21 -0
- main.py +57 -0
- melasma-486x573.jpeg +0 -0
- requirements.txt +6 -0
.gitignore
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --- Sensitive Information ---
|
| 2 |
+
# Ignore environment files containing secrets like API keys or tokens.
|
| 3 |
+
.env
|
| 4 |
+
*.env
|
| 5 |
+
.env.*
|
| 6 |
+
|
| 7 |
+
# --- Python Virtual Environments ---
|
| 8 |
+
# A virtual environment should not be committed.
|
| 9 |
+
# Instead, commit a requirements.txt file.
|
| 10 |
+
/venv/
|
| 11 |
+
/env/
|
| 12 |
+
/.venv/
|
| 13 |
+
/.gradio/
|
| 14 |
+
/ENV/
|
| 15 |
+
|
| 16 |
+
# --- Python Artifacts ---
|
| 17 |
+
# Ignore Python cache and compiled files.
|
| 18 |
+
__pycache__/
|
| 19 |
+
*.pyc
|
| 20 |
+
*.pyo
|
| 21 |
+
*.pyd
|
| 22 |
+
*.egg-info/
|
| 23 |
+
dist/
|
| 24 |
+
build/
|
| 25 |
+
|
| 26 |
+
# --- Models & Data ---
|
| 27 |
+
# Ignore large model files. These should be downloaded or loaded from a remote source.
|
| 28 |
+
*.onnx
|
| 29 |
+
*.pt
|
| 30 |
+
*.pth
|
| 31 |
+
*.h5
|
| 32 |
+
|
| 33 |
+
# Ignore datasets. These are typically too large for version control.
|
| 34 |
+
# You can uncomment the line below if your data is in a 'data/' folder.
|
| 35 |
+
# /data/
|
| 36 |
+
|
| 37 |
+
# --- IDE & Editor Configuration ---
|
| 38 |
+
# Ignore configuration files from common editors like VSCode and PyCharm.
|
| 39 |
+
.vscode/
|
| 40 |
+
.idea/
|
| 41 |
+
|
| 42 |
+
# --- Jupyter Notebook Checkpoints ---
|
| 43 |
+
.ipynb_checkpoints/
|
| 44 |
+
|
| 45 |
+
# --- Operating System Files ---
|
| 46 |
+
# Ignore OS-specific files.
|
| 47 |
+
.DS_Store
|
| 48 |
+
Thumbs.db
|
| 49 |
+
|
| 50 |
+
# --- Log Files ---
|
| 51 |
+
# Ignore log files, which can become large and are specific to a run.
|
| 52 |
+
*.log
|
README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2025-iskyn
|
| 2 |
+
|
| 3 |
+
Minimal structure for running ONNX image inference with a simple CLI.
|
| 4 |
+
|
| 5 |
+
## Setup
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
python -m venv .venv
|
| 9 |
+
source .venv/bin/activate
|
| 10 |
+
pip install -r requirements.txt
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
## Predict with ONNX
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
python main.py --model best.onnx --image path/to/image.jpg --output out.png
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
`detect_objects` currently returns the input image unchanged. Implement your model-specific post-processing in `src/iskyn/inference/onnx_runtime.py`.
|
| 20 |
+
|
| 21 |
+
|
main.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import cv2
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from ultralytics import YOLO
|
| 5 |
+
import os
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
print("Loading environment variables...")
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
HF_REPO_ID = "tententgc/Iskyn"
|
| 14 |
+
MODEL_FILENAME = "best.onnx"
|
| 15 |
+
|
| 16 |
+
print(f"Downloading '{MODEL_FILENAME}' from '{HF_REPO_ID}'...")
|
| 17 |
+
|
| 18 |
+
model_path = hf_hub_download(
|
| 19 |
+
repo_id=HF_REPO_ID,
|
| 20 |
+
filename=MODEL_FILENAME,
|
| 21 |
+
token=os.getenv("HF_TOKEN")
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
print(f"Model downloaded to: {model_path}")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
print("Loading YOLO model...")
|
| 29 |
+
onnx_model = YOLO(model_path)
|
| 30 |
+
print("Model loaded successfully.")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def predict_image(image_filepath, conf_threshold, iou_threshold):
|
| 35 |
+
results = onnx_model.predict(
|
| 36 |
+
image_filepath,
|
| 37 |
+
conf=conf_threshold,
|
| 38 |
+
iou=iou_threshold
|
| 39 |
+
)
|
| 40 |
+
result = results[0]
|
| 41 |
+
im_array = result.plot()
|
| 42 |
+
im_rgb = cv2.cvtColor(im_array, cv2.COLOR_BGR2RGB)
|
| 43 |
+
return im_rgb
|
| 44 |
+
|
| 45 |
+
iface = gr.Interface(
|
| 46 |
+
fn=predict_image,
|
| 47 |
+
inputs=[
|
| 48 |
+
gr.Image(type="filepath", label="Upload Image"),
|
| 49 |
+
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence Threshold"),
|
| 50 |
+
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU Threshold")
|
| 51 |
+
],
|
| 52 |
+
outputs=gr.Image(type="numpy", label="Result"),
|
| 53 |
+
title="Detection Face Skin",
|
| 54 |
+
description="Upload an image and adjust the thresholds to fine-tune detection."
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
iface.launch()
|
melasma-486x573.jpeg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
onnxruntime>=1.18.0
|
| 2 |
+
numpy>=1.26.0
|
| 3 |
+
opencv-python>=4.9.0.80
|
| 4 |
+
Pillow>=10.3.0
|
| 5 |
+
gradio>=4.44.0
|
| 6 |
+
|