Comments (13)
boxes[:, 0] = torch.where(boxes[:, 0] < threshold, torch.tensor(0,dtype=torch.float,device=boxes.device), boxes[:, 0]) # x1
boxes[:, 1] = torch.where(boxes[:, 1] < threshold, torch.tensor(0,dtype=torch.float,device=boxes.device), boxes[:, 1]) # y1
boxes[:, 2] = torch.where(boxes[:, 2] > w - threshold, torch.tensor(w,dtype=torch.float,device=boxes.device), boxes[:, 2]) # x2
boxes[:, 3] = torch.where(boxes[:, 3] > h - threshold, torch.tensor(h,dtype=torch.float,device=boxes.device), boxes[:, 3]) # y2
is ok
from fastsam.
Hi @syntherick , this appears to be a bug in the code, and we will resolve it as soon as possible. Could you please provide the inference code or command you used? This information would be very helpful for us to investigate the issue.
from fastsam.
Hi @berry-ding, I get the error for either of following:
!python ./Inference.py --model_path ../FastSAM-x.pt --img_path ./image.jpg --imgsz 1024
and
from fastsam import FastSAM, FastSAMPrompt
model = FastSAM('../FastSAM-x.pt')
IMAGE_PATH = './image.jpg'
DEVICE = '0'
everything_results = model(IMAGE_PATH, device=DEVICE, retina_masks=True, imgsz=1024, conf=0.4, iou=0.9,)
from fastsam.
Hello @syntherick , we have retested and were unable to reproduce the issue. Could you please git pull the latest version of the code and try again? If the problem persists, it might be a bug triggered by specific images. Could you please share the image that caused the problem with us?
from fastsam.
I don't why, but I changed the code in utils.py 17-20, then it works well.
Adjust boxes
boxes[:, 0] = torch.where(boxes[:, 0] < threshold, torch.tensor(0,dtype=torch.float), boxes[:, 0]) # x1
boxes[:, 1] = torch.where(boxes[:, 1] < threshold, torch.tensor(0,dtype=torch.float), boxes[:, 1]) # y1
boxes[:, 2] = torch.where(boxes[:, 2] > w - threshold, torch.tensor(w,dtype=torch.float), boxes[:, 2]) # x2
boxes[:, 3] = torch.where(boxes[:, 3] > h - threshold, torch.tensor(h,dtype=torch.float), boxes[:, 3]) # y2
from fastsam.
@berry-ding Here is the image which I used
from fastsam.
Hi, I have the exactly same error.
from fastsam.
I don't why, but I changed the code in utils.py 17-20, then it works well.
Adjust boxes
boxes[:, 0] = torch.where(boxes[:, 0] < threshold, torch.tensor(0,dtype=torch.float), boxes[:, 0]) # x1 boxes[:, 1] = torch.where(boxes[:, 1] < threshold, torch.tensor(0,dtype=torch.float), boxes[:, 1]) # y1 boxes[:, 2] = torch.where(boxes[:, 2] > w - threshold, torch.tensor(w,dtype=torch.float), boxes[:, 2]) # x2 boxes[:, 3] = torch.where(boxes[:, 3] > h - threshold, torch.tensor(h,dtype=torch.float), boxes[:, 3]) # y2
There will be bugs again again running on cuda devices
from fastsam.
I meet the same proble , when use the inference demo you provide
from fastsam import FastSAM, FastSAMPrompt
model = FastSAM('./weights/FastSAM.pt')
IMAGE_PATH = './images/dogs.jpg'
DEVICE = 'cpu'
everything_results = model(IMAGE_PATH, device=DEVICE, retina_masks=True, imgsz=1024, conf=0.4, iou=0.9,)
prompt_process = FastSAMPrompt(IMAGE_PATH, everything_results, device=DEVICE)
# everything prompt
ann = prompt_process.everything_prompt()
# bbox default shape [0,0,0,0] -> [x1,y1,x2,y2]
ann = prompt_process.box_prompt(bbox=[200, 200, 300, 300])
# text prompt
ann = prompt_process.text_prompt(text='a photo of a dog')
# point prompt
# points default [[0,0]] [[x1,y1],[x2,y2]]
# point_label default [0] [1,0] 0:background, 1:foreground
ann = prompt_process.point_prompt(points=[[620, 360]], pointlabel=[1])
prompt_process.plot(annotations=ann,output='./output/',)
And it show runtimeerror like this
File "inference_demo.py", line 6, in
everything_results = model(IMAGE_PATH, device=DEVICE, retina_masks=True, imgsz=1024, conf=0.4, iou=0.9,)
File "E:\OroChiLab\FastSAM\fastsam\model.py", line 99, in call
return self.predict(source, stream, **kwargs)
File "C:\ProgramData\miniconda3\envs\torch-py37\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "E:\OroChiLab\FastSAM\fastsam\model.py", line 51, in predict
return self.predictor(source, stream=stream)
File "C:\ProgramData\miniconda3\envs\torch-py37\lib\site-packages\ultralytics\yolo\engine\predictor.py", line 184, in call
return list(self.stream_inference(source, model)) # merge list of Result into one
File "C:\ProgramData\miniconda3\envs\torch-py37\lib\site-packages\torch\autograd\grad_mode.py", line 43, in generator_context
response = gen.send(None)
File "C:\ProgramData\miniconda3\envs\torch-py37\lib\site-packages\ultralytics\yolo\engine\predictor.py", line 244, in stream_inference
self.results = self.postprocess(preds, im, im0s)
File "E:\OroChiLab\FastSAM\fastsam\predict.py", line 27, in postprocess
critical_iou_index = bbox_iou(full_box[0][:4], p[0][:, :4], iou_thres=0.9, image_shape=img.shape[2:])
File "E:\OroChiLab\FastSAM\fastsam\utils.py", line 50, in bbox_iou
boxes = adjust_bboxes_to_image_border(boxes, image_shape)
File "E:\OroChiLab\FastSAM\fastsam\utils.py", line 19, in adjust_bboxes_to_image_border
boxes[:, 0] = torch.where(boxes[:, 0] < threshold, 0, boxes[:, 0]) # x1
RuntimeError: expected scalar type __int64 but found float
from fastsam.
boxes[:, 0] = torch.where(boxes[:, 0] < threshold, torch.tensor(0,dtype=torch.float,device=boxes.device), boxes[:, 0]) # x1 boxes[:, 1] = torch.where(boxes[:, 1] < threshold, torch.tensor(0,dtype=torch.float,device=boxes.device), boxes[:, 1]) # y1 boxes[:, 2] = torch.where(boxes[:, 2] > w - threshold, torch.tensor(w,dtype=torch.float,device=boxes.device), boxes[:, 2]) # x2 boxes[:, 3] = torch.where(boxes[:, 3] > h - threshold, torch.tensor(h,dtype=torch.float,device=boxes.device), boxes[:, 3]) # y2
is ok
It worked thanks for your answer😋
from fastsam.
We would close this issue for now to keep the issue tracker organized. However, if the problem persists or if you have any further questions, please feel free to comment here or open a new issue. We value your input and are happy to assist further.
from fastsam.
the same problem:
Traceback (most recent call last):
File "Inference.py", line 119, in
main(args)
File "Inference.py", line 79, in main
everything_results = model(
File "/home/rui.li/projects/FastSAM/fastsam/model.py", line 99, in call
return self.predict(source, stream, **kwargs)
File "/home/rui.li/projects/FastSAM/venv/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "/home/rui.li/projects/FastSAM/fastsam/model.py", line 51, in predict
return self.predictor(source, stream=stream)
File "/home/rui.li/projects/FastSAM/venv/lib/python3.8/site-packages/ultralytics/yolo/engine/predictor.py", line 188, in call
return list(self.stream_inference(source, model)) # merge list of Result into one
File "/home/rui.li/projects/FastSAM/venv/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 45, in generator_context
response = gen.send(None)
File "/home/rui.li/projects/FastSAM/venv/lib/python3.8/site-packages/ultralytics/yolo/engine/predictor.py", line 248, in stream_inference
self.results = self.postprocess(preds, im, im0s)
File "/home/rui.li/projects/FastSAM/fastsam/predict.py", line 31, in postprocess
critical_iou_index = bbox_iou(full_box[0][:4], p[0][:, :4], iou_thres=0.9, image_shape=img.shape[2:])
File "/home/rui.li/projects/FastSAM/fastsam/utils.py", line 39, in bbox_iou
boxes = adjust_bboxes_to_image_border(boxes, image_shape)
File "/home/rui.li/projects/FastSAM/fastsam/utils.py", line 17, in adjust_bboxes_to_image_border
boxes[:, 0] = torch.where(boxes[:, 0] < threshold, 0, boxes[:, 0]) # x1
RuntimeError: expected scalar type long int but found float
from fastsam.
我不知道为什么,但我更改了 utils.py 17-20 中的代码,然后它就可以正常工作了。
调整盒
boxes[:, 0] = torch.where(boxes[:, 0] < threshold, torch.tensor(0,dtype=torch.float), boxes[:, 0]) # x1 boxes[:, 1] = torch.where(boxes[:, 1] < threshold, torch.tensor(0,dtype=torch.float), boxes[:, 1]) # y1 boxes[:, 2] = torch.where(boxes[:, 2] > w - threshold, torch.tensor(w,dtype=torch.float), boxes[:, 2]) # x2 boxes[:, 3] = torch.where(boxes[:, 3] > h - threshold, torch.tensor(h,dtype=torch.float), boxes[:, 3]) # y2
Thank you! we have fixed our codes.
from fastsam.
Related Issues (20)
- Problems during training
- Assertion Error
- Model returns None when used in Google Colab
- text model is not correct box
- How to convert annotation files of the SA-1B dataset into the format compatible with YOLOv8
- about network: FastSAM is only to train a YOLOV8-seg? HOT 17
- SA-1B dataset HOT 1
- Working with FastSAM results HOT 2
- visualize mask branch
- Why the number of parameters of FastSAM different from Yolov8-seg?
- fine-tuning FastSAM with medical CT scans
- Hello, I am trying to reproduce your validation data on the coco dataset, but I have encountered the following problems
- Hello, I am using the verification code published by you, but I have encountered many problems. Could you please publish a usage instruction document Thank you.
- whole image predict
- Return Nothing With CUDA DEVICE
- Finetuning the CLIP model used in FastSAM
- Segment by similarity to a reference image
- Where is the tensorrt C++ deployment
- Wrong license in readme after commit 279ceab2b656801917fd2d84e182a80f5d20bf8a HOT 1
- object proposal cocoeval - how did you get your SAM result? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastsam.