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

[Typing][A-87] Add type annotations for python/paddle/vision/datasets/flowers.py #65504

Merged
merged 3 commits into from
Jun 28, 2024

Conversation

enkilee
Copy link
Contributor

@enkilee enkilee commented Jun 27, 2024

PR Category

User Experience

PR Types

Improvements

Description

Copy link

paddle-bot bot commented Jun 27, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

这个错误

2024-06-27 09:50:04 paddle.vision.datasets.Flowers:1
2024-06-27 09:50:04 <string>:30:22: error: Item "Image" of "Union[Tensor, Image, ndarray[Any, dtype[Any]]]" has no attribute "shape"  [union-attr]
2024-06-27 09:50:04 Found 1 error in 1 file (checked 1 source file)

目前我能想到的解决办法:

  • 在示例中的 ... print(type(img), img.shape, label) 加上 # type: ignore
  • cast... print(type(img), cast(Tensor, img).shape, label)

@SigureMo 帮忙看看?

@@ -167,7 +187,7 @@ def __init__(
self.labels = scio.loadmat(label_file)['labels'][0]
self.indexes = scio.loadmat(setid_file)[flag][0]

def __getitem__(self, idx):
def __getitem__(self, idx: int) -> tuple[_ImageDataType, npt.NDArray[Any]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def __getitem__(self, idx: int) -> tuple[_ImageDataType, npt.NDArray[Any]]:
def __getitem__(self, idx: int) -> tuple[_ImageDataType, npt.NDArray[np.int64]]:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到

@SigureMo
Copy link
Member

在示例中的 ... print(type(img), img.shape, label) 加上 # type: ignore

ignore 吧

@SigureMo
Copy link
Member

2024-06-28 09:23:24 ----------------Check results--------------------
2024-06-28 09:23:24 paddle.vision.datasets.Flowers:1
2024-06-28 09:23:24 <string>:9: error: Unused "type: ignore" comment  [unused-ignore]
2024-06-28 09:23:24 <string>:30:22: error: Item "Image" of "Union[Tensor, Image, ndarray[Any, dtype[Any]]]" has no attribute "shape"  [union-attr]
2024-06-28 09:23:24 Found 2 errors in 1 file (checked 1 source file)
2024-06-28 09:23:24 
2024-06-28 09:23:24 
2024-06-28 09:23:24 >>> Mistakes found in type checking!
2024-06-28 09:23:24 >>> Please recheck the type annotations. Run `tools/type_checking.py` to check the typing issues:

加错地方了,注意下行号

@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Jun 28, 2024
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@SigureMo SigureMo merged commit 6d40b68 into PaddlePaddle:develop Jun 28, 2024
30 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants