Code Monkey home page Code Monkey logo

Comments (13)

d710055071 avatar d710055071 commented on July 28, 2024 2
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.

berry-ding avatar berry-ding commented on July 28, 2024

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.

syntherick avatar syntherick commented on July 28, 2024

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.

berry-ding avatar berry-ding commented on July 28, 2024

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.

jq-learning avatar jq-learning commented on July 28, 2024

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.

syntherick avatar syntherick commented on July 28, 2024

@berry-ding Here is the image which I used
image

from fastsam.

ggsDing avatar ggsDing commented on July 28, 2024

Hi, I have the exactly same error.

from fastsam.

ggsDing avatar ggsDing commented on July 28, 2024

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.

OroChippw avatar OroChippw commented on July 28, 2024

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.

OroChippw avatar OroChippw commented on July 28, 2024
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.

an-yongqi avatar an-yongqi commented on July 28, 2024

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.

susufqx avatar susufqx commented on July 28, 2024

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.

berry-ding avatar berry-ding commented on July 28, 2024

我不知道为什么,但我更改了 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.