If your script expects `--local_rank` argument to be set, please change it to read from `os.environ['LOCAL_RANK']` instead. See
时间: 2024-05-22 12:10:31 浏览: 526
这个提示的意思是如果你的脚本需要设置`--local_rank`参数,那么你应该更新你的脚本,使其从`os.environ['LOCAL_RANK']`环境变量中获取该参数的值。这是因为在分布式训练中,`--local_rank`参数通常是通过环境变量传递的,而不是通过命令行参数传递的。这个提示提醒你在分布式训练中正确地获取`--local_rank`参数的值,以便你的脚本能够正确地运行。
相关问题
FutureWarning: The module torch.distributed.launch is deprecated and will be removed in future. Use torchrun. Note that --use-env is set by default in torchrun. If your script expects `--local-rank` argument to be set, please change it to read from `os.environ['LOCAL_RANK']` instead. See https://pytorch.org/docs/stable/distributed.html#launch-utility for further instructions
这个警告提示表示 torch.distributed.launch 模块已被弃,并将在未来的中删除。建议 torchrun 替代它。
使用 torchrun 时,默认情况下,--use-env 选项已经被设置好了。如果你的脚本期设置 --local-rank 参数,请为从 os.environ[''] 中读取该值。可以在这里参考更多的指令:https://pytorch.org/docs/stable/distributed.html#launch-utility
建议你更新你的代码,使用 torchrun 来启动分布式训练,并根据警告信息中的指引来进行相应的修改。
如果你有任何其他问题,请随时提问。
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[11], line 1 ----> 1 predictor.set_image("bingbao.jpg") File /workspace/segment-anything/segment_anything/predictor.py:56, in SamPredictor.set_image(self, image, image_format) 53 image = image[..., ::-1] 55 # Transform the image to the form expected by the model ---> 56 input_image = self.transform.apply_image(image) 57 input_image_torch = torch.as_tensor(input_image, device=self.device) 58 input_image_torch = input_image_torch.permute(2, 0, 1).contiguous()[None, :, :, :] File /workspace/segment-anything/segment_anything/utils/transforms.py:30, in ResizeLongestSide.apply_image(self, image) 26 def apply_image(self, image: np.ndarray) -> np.ndarray: 27 """ 28 Expects a numpy array with shape HxWxC in uint8 format. 29 """ ---> 30 target_size = self.get_preprocess_shape(image.shape[0], image.shape[1], self.target_length) 31 return np.array(resize(to_pil_image(image), target_size)) AttributeError: 'str' object has no attribute 'shape'
这是一个Python的AttributeError错误,错误信息显示在predictor.py的第56行,因为传递给set_image方法的参数是一个字符串而不是numpy数组,因此在apply_image方法中调用image.shape时会出错。解决方法是在调用set_image方法之前将图像转换为numpy数组。例如,可以使用OpenCV库中的imread方法读取图像并将其转换为numpy数组。
阅读全文