ZhengPeng7 commited on
Commit
33f3505
·
1 Parent(s): 88e5141

Turn on half precision.

Browse files
Files changed (2) hide show
  1. app.py +3 -3
  2. app_local.py +3 -3
app.py CHANGED
@@ -87,7 +87,7 @@ usage_to_weights_file = {
87
 
88
  birefnet = AutoModelForImageSegmentation.from_pretrained('/'.join(('zhengpeng7', usage_to_weights_file['General'])), trust_remote_code=True)
89
  birefnet.to(device)
90
- birefnet.eval()
91
 
92
 
93
  @spaces.GPU
@@ -100,7 +100,7 @@ def predict(images, resolution, weights_file):
100
  print('Using weights: {}.'.format(_weights_file))
101
  birefnet = AutoModelForImageSegmentation.from_pretrained(_weights_file, trust_remote_code=True)
102
  birefnet.to(device)
103
- birefnet.eval()
104
 
105
  try:
106
  resolution = [int(int(reso)//32*32) for reso in resolution.strip().split('x')]
@@ -143,7 +143,7 @@ def predict(images, resolution, weights_file):
143
 
144
  # Prediction
145
  with torch.no_grad():
146
- preds = birefnet(image_proc.to(device))[-1].sigmoid().cpu()
147
  pred = preds[0].squeeze()
148
 
149
  # Show Results
 
87
 
88
  birefnet = AutoModelForImageSegmentation.from_pretrained('/'.join(('zhengpeng7', usage_to_weights_file['General'])), trust_remote_code=True)
89
  birefnet.to(device)
90
+ birefnet.eval(); birefnet.half()
91
 
92
 
93
  @spaces.GPU
 
100
  print('Using weights: {}.'.format(_weights_file))
101
  birefnet = AutoModelForImageSegmentation.from_pretrained(_weights_file, trust_remote_code=True)
102
  birefnet.to(device)
103
+ birefnet.eval(); birefnet.half()
104
 
105
  try:
106
  resolution = [int(int(reso)//32*32) for reso in resolution.strip().split('x')]
 
143
 
144
  # Prediction
145
  with torch.no_grad():
146
+ preds = birefnet(image_proc.to(device).half())[-1].sigmoid().cpu()
147
  pred = preds[0].squeeze()
148
 
149
  # Show Results
app_local.py CHANGED
@@ -87,7 +87,7 @@ usage_to_weights_file = {
87
 
88
  birefnet = AutoModelForImageSegmentation.from_pretrained('/'.join(('zhengpeng7', usage_to_weights_file['General'])), trust_remote_code=True)
89
  birefnet.to(device)
90
- birefnet.eval()
91
 
92
 
93
  # @spaces.GPU
@@ -100,7 +100,7 @@ def predict(images, resolution, weights_file):
100
  print('Using weights: {}.'.format(_weights_file))
101
  birefnet = AutoModelForImageSegmentation.from_pretrained(_weights_file, trust_remote_code=True)
102
  birefnet.to(device)
103
- birefnet.eval()
104
 
105
  try:
106
  resolution = [int(int(reso)//32*32) for reso in resolution.strip().split('x')]
@@ -143,7 +143,7 @@ def predict(images, resolution, weights_file):
143
 
144
  # Prediction
145
  with torch.no_grad():
146
- preds = birefnet(image_proc.to(device))[-1].sigmoid().cpu()
147
  pred = preds[0].squeeze()
148
 
149
  # Show Results
 
87
 
88
  birefnet = AutoModelForImageSegmentation.from_pretrained('/'.join(('zhengpeng7', usage_to_weights_file['General'])), trust_remote_code=True)
89
  birefnet.to(device)
90
+ birefnet.eval(); birefnet.half()
91
 
92
 
93
  # @spaces.GPU
 
100
  print('Using weights: {}.'.format(_weights_file))
101
  birefnet = AutoModelForImageSegmentation.from_pretrained(_weights_file, trust_remote_code=True)
102
  birefnet.to(device)
103
+ birefnet.eval(); birefnet.half()
104
 
105
  try:
106
  resolution = [int(int(reso)//32*32) for reso in resolution.strip().split('x')]
 
143
 
144
  # Prediction
145
  with torch.no_grad():
146
+ preds = birefnet(image_proc.to(device).half())[-1].sigmoid().cpu()
147
  pred = preds[0].squeeze()
148
 
149
  # Show Results