rayh commited on
Commit
933bb62
·
unverified ·
1 Parent(s): 5d466d9

Ok, try this

Browse files
astro-20250209-seg.pt DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:c71465d7cd15546cdc30165ef23248b3cd8598b9d744c2383c643d3b79a1355a
3
- size 45236271
 
 
 
 
astro-20250209-seg.onnx → astro-yolo11m-seg.onnx RENAMED
File without changes
config.json CHANGED
@@ -1 +1,8 @@
1
- {"model_type": "YOLOv11-Segmentation", "framework": "pytorch", "architecture": "YOLO", "image_size": 640, "num_classes": 2}
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "YOLOTransformersModel"
4
+ ],
5
+ "model_type": "yolo-segmentation",
6
+ "onnx_model": "astro-yolo11m-seg.onnx",
7
+ "task": "image-segmentation"
8
+ }
inference.py DELETED
@@ -1,17 +0,0 @@
1
- from ultralytics import YOLO
2
- from PIL import Image
3
- import torch
4
-
5
- # Load model from the same directory as this script
6
- MODEL_PATH = "pytorch_model.bin"
7
-
8
- class YOLOSegmentation:
9
- def __init__(self):
10
- self.model = YOLO(MODEL_PATH) # Load YOLO model
11
-
12
- def __call__(self, image: Image.Image):
13
- results = self.model(image) # Run inference
14
- return results[0].tojson() # Convert output to JSON format
15
-
16
- # Hugging Face Inference API expects a `model` variable
17
- model = YOLOSegmentation()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
model-index.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "model-index": [
3
- {
4
- "name": "YOLOv11 Segmentation Model",
5
- "library_name": "ultralytics",
6
- "pipeline_tag": "image-segmentation",
7
- "tags": ["object-detection", "segmentation", "YOLO"]
8
- }
9
- ]
10
- }
 
 
 
 
 
 
 
 
 
 
 
modelling_yolo.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import onnxruntime as ort
3
+ from transformers import PreTrainedModel, PretrainedConfig
4
+ from PIL import Image
5
+ import numpy as np
6
+
7
+ class YOLOConfig(PretrainedConfig):
8
+ model_type = "yolo-segmentation"
9
+
10
+ class YOLOTransformersModel(PreTrainedModel):
11
+ config_class = YOLOConfig
12
+
13
+ def __init__(self, config):
14
+ super().__init__(config)
15
+ self.session = ort.InferenceSession(config.onnx_model, providers=["CPUExecutionProvider"])
16
+
17
+ def forward(self, images):
18
+ input_array = np.array(images.convert("RGB")).astype(np.float32)
19
+ input_array = np.expand_dims(input_array, axis=0) # Add batch dimension
20
+
21
+ outputs = self.session.run(None, {"images": input_array})
22
+ return outputs # Modify as needed to match Transformers format
pytorch_model.bin DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:c71465d7cd15546cdc30165ef23248b3cd8598b9d744c2383c643d3b79a1355a
3
- size 45236271
 
 
 
 
requirements.txt CHANGED
@@ -1,3 +1,6 @@
1
- ultralytics>=8.0.0
2
- torch>=2.0.0
3
- pillow
 
 
 
 
1
+ ultralytics
2
+ transformers
3
+ onnxruntime
4
+ torch
5
+ numpy
6
+ Pillow