Leyogho commited on
Commit
0e5ebd8
1 Parent(s): 6b4e8f4

Change interface

Browse files
app.py CHANGED
@@ -53,7 +53,6 @@ def init_huggingface():
53
  )
54
  return pretrained_path
55
 
56
- @torch.no_grad()
57
  @spaces.GPU
58
  def init_distributed(opt):
59
  opt['CUDA'] = opt.get('CUDA', True) and torch.cuda.is_available()
@@ -88,10 +87,10 @@ def init_distributed(opt):
88
  def setup_model():
89
  """Initialize the model on CPU without CUDA initialization."""
90
  opt = load_opt_from_config_files(["configs/biomedparse_inference.yaml"])
91
- opt['CUDA'] = opt.get('CUDA', True) and torch.cuda.is_available() # Vérifier la disponibilité de CUDA
92
  opt = init_distributed(opt)
 
93
  pretrained_path = init_huggingface()
94
- model = BaseModel(opt, build_model(opt)).from_pretrained(pretrained_path)
95
  return model
96
 
97
  @torch.no_grad()
@@ -146,6 +145,7 @@ def predict_image(model, image, prompts):
146
  mode='bilinear')[0,:,:data['height'],:data['width']].sigmoid().cpu().detach().numpy()
147
  return pred_mask_prob
148
 
 
149
  def process_image(image, prompts, model):
150
  """Process image with proper error handling."""
151
  try:
 
53
  )
54
  return pretrained_path
55
 
 
56
  @spaces.GPU
57
  def init_distributed(opt):
58
  opt['CUDA'] = opt.get('CUDA', True) and torch.cuda.is_available()
 
87
  def setup_model():
88
  """Initialize the model on CPU without CUDA initialization."""
89
  opt = load_opt_from_config_files(["configs/biomedparse_inference.yaml"])
 
90
  opt = init_distributed(opt)
91
+ opt['device'] = 'cuda' if torch.cuda.is_available() else 'cpu'
92
  pretrained_path = init_huggingface()
93
+ model = BaseModel(opt, build_model(opt)).from_pretrained(pretrained_path).eval()
94
  return model
95
 
96
  @torch.no_grad()
 
145
  mode='bilinear')[0,:,:data['height'],:data['width']].sigmoid().cpu().detach().numpy()
146
  return pred_mask_prob
147
 
148
+
149
  def process_image(image, prompts, model):
150
  """Process image with proper error handling."""
151
  try:
modeling/architectures/seem_model_demo.py CHANGED
@@ -134,8 +134,9 @@ class GeneralizedSEEM(nn.Module):
134
  interactive_mode = 'best'
135
  interactive_iter = 20
136
  dilation = 3
137
- dilation_kernel = torch.ones((1, 1, dilation, dilation), device=torch.cuda.current_device())
138
-
 
139
  return {
140
  "backbone": backbone,
141
  "sem_seg_head": sem_seg_head,
 
134
  interactive_mode = 'best'
135
  interactive_iter = 20
136
  dilation = 3
137
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
138
+ dilation_kernel = torch.ones((1, 1, dilation, dilation), device=device)
139
+
140
  return {
141
  "backbone": backbone,
142
  "sem_seg_head": sem_seg_head,
requirements.txt CHANGED
@@ -1,5 +1,4 @@
1
  pillow==9.4.0
2
- accelerate
3
  opencv-python==4.8.1.78
4
  pyyaml==6.0.1
5
  json_tricks==3.17.3
@@ -15,7 +14,6 @@ sentencepiece==0.1.99
15
  ftfy==6.1.1
16
  regex==2023.10.3
17
  nltk==3.8.1
18
- #mpi4py
19
  vision-datasets==0.2.2
20
  cython==3.0.2
21
  pycocotools==2.0.7
 
1
  pillow==9.4.0
 
2
  opencv-python==4.8.1.78
3
  pyyaml==6.0.1
4
  json_tricks==3.17.3
 
14
  ftfy==6.1.1
15
  regex==2023.10.3
16
  nltk==3.8.1
 
17
  vision-datasets==0.2.2
18
  cython==3.0.2
19
  pycocotools==2.0.7