Kelex83 commited on
Commit
1e92f3d
·
verified ·
1 Parent(s): 9159cfb

Update model.py

Browse files

Used pipeline to load model

Files changed (1) hide show
  1. model.py +12 -7
model.py CHANGED
@@ -1,5 +1,6 @@
1
  import albumentations as A
2
  from transformers import AutoModelForObjectDetection, AutoImageProcessor
 
3
 
4
 
5
  # Mapping for labels and IDs
@@ -52,11 +53,15 @@ def get_val_transform():
52
  )
53
 
54
  # Load the model
55
- def load_model():
56
- model_path = "sergiopaniego/detr-resnet-50-dc5-fashionpedia-finetuned" # Path to your saved model
57
- image_processor = AutoImageProcessor.from_pretrained(model_path)
58
- model = AutoModelForObjectDetection.from_pretrained(
59
- model_path, # This will automatically use model.safetensors
60
- ignore_mismatched_sizes=True
 
 
 
 
61
  )
62
- return model, image_processor
 
1
  import albumentations as A
2
  from transformers import AutoModelForObjectDetection, AutoImageProcessor
3
+ from transformers import pipeline
4
 
5
 
6
  # Mapping for labels and IDs
 
53
  )
54
 
55
  # Load the model
56
+ def load_model(device: int = -1):
57
+ """
58
+ Load the DETR model pipeline.
59
+ :param device: Specify device to load the model (-1 for CPU, 0 for GPU).
60
+ :return: Hugging Face object-detection pipeline.
61
+ """
62
+ model_pipeline = pipeline(
63
+ "object-detection",
64
+ model="sergiopaniego/detr-resnet-50-dc5-fashionpedia-finetuned",
65
+ device=device
66
  )
67
+ return model_pipeline