facebookresearch / facebookresearch/segment-anything

run with "mps" is error:Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

Open
#94 27 comments 23 reactions 0 assignees View on GitHub
question
Dominant language
Jupyter Notebook
Stars
54.9k
Forks
6.4k
PR merge metrics
No merged PRs in 30d

Description

when I follow the [automatic_mask_generator_example](https://github.com/facebookresearch/segment-anything/blob/main/notebooks/automatic_mask_generator_example.ipynb) to generating masks, It works in my rtx3080 and m1pro's cpu, but when I change the device to 'mps',the error is show:"**Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead."**

this is my code:
```
# 打开图片并转换为numpy数组
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# get image_path name
file_name = os.path.splitext(os.path.basename(image_path))[0]
# 创建 output 文件夹(如果不存在)
image_folder = os.path.join(OutPutFolder, file_name)
check_floder(image_folder)

# 获取当前时间戳
start_time = time.time()

# 根据输入图像生成多个区域掩码
masks = mask_generator.generate(image) ###### **error in here**

# 获取当前时间戳并计算消耗时间
end_time = time.time()
elapsed_time = end_time - start_time

print(f"Time elapsed for mask_generator.generate{file_name}: {elapsed_time:.2f} seconds")

# 创建一个空白图像,用于存储融合的结果
result_image = np.zeros_like(image, dtype=np.float32)
```

Contributor guide

Open the contributing guide

Research direction

Start with automatic_mask_generator_example.ipynb and reproduce the failure at mask_generator.generate(image) using the MPS device. Trace the tensor dtype at that call and compare it with the reported float64 limitation; done means the example generates masks successfully on MPS without the conversion error.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python, pytorch
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.