Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix image read error #3377

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions paddleseg/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def __call__(self, data):
if 'img' not in data.keys():
raise ValueError("`data` must include `img` key.")
if isinstance(data['img'], str):
data['img'] = cv2.imread(data['img'],
self.read_flag).astype('float32')
if data['img'] is None:
raise ValueError('Can\'t read The image file {}!'.format(data[
'img']))
img = cv2.imread(data['img'], self.read_flag)
if img is None:
raise ValueError('Can\'t read The image file {}!'.format(data['img']))
data['img'] = img.astype('float32')
Comment on lines +68 to +70
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个修改会导致一个不兼容问题,目前eg1800和supervisely在调用compose时传入的是传入image,而不是string,因此这样修改会导致漏掉对image的判None操作,建议:

  1. 同步修改eg1800和supervisely传入path而不是image。
  2. 加入assert指令保证img为string类型。
  3. 删除if isinstance(data['img'], str)

从而所有传入的都是sting,并在加载string后进行判断是否None,不为None则astype。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eg1800和supervisely的逻辑似乎不太方便修改为只传入string,因此多加了一个判断


if not isinstance(data['img'], np.ndarray):
raise TypeError("Image type is not numpy.")

Expand Down