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-88] Add type annotations for python/paddle/vision/datasets/folder.py #65532

Merged
merged 7 commits into from
Jul 6, 2024

Conversation

enkilee
Copy link
Contributor

@enkilee enkilee commented Jun 28, 2024

PR Category

User Experience

PR Types

Improvements

Description

Copy link

paddle-bot bot commented Jun 28, 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.

@paddle-bot paddle-bot bot added the contributor External developers label Jun 28, 2024
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Jun 28, 2024
python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
python/paddle/vision/datasets/folder.py Show resolved Hide resolved
@megemini
Copy link
Contributor

示例中有两个地方可能要 ignore 一下:

            >>> data_folder_2 = DatasetFolder(
            ...     fake_data_dir,
            ...     loader=lambda x: cv2.imread(x),  # load image with OpenCV
            ...     extensions=(".jpg",),  # type: ignore # only load *.jpg files 
            ...     transform=transform,  # apply transform to every image
            ... )

            >>> print([img_path for img_path, label in data_folder_2.samples])
            >>> # doctest: +SKIP(it's different with windows)
            ['./temp_dir/class_0/abc.jpg', './temp_dir/class_1/mno/stu.jpg']
            >>> # doctest: -SKIP
            >>> print(len(data_folder_2))
            2

            >>> for img, label in iter(data_folder_2):
            ...     # do something with img and label
            ...     print(type(img), img.shape, label) # type: ignore
            ...     # <class 'paddle.Tensor'> [3, 64, 64] 0

@megemini
Copy link
Contributor

ImageFolder 的示例也要改一下滴 ~~~

@megemini
Copy link
Contributor

megemini commented Jul 1, 2024

@enkilee

... print(type(img), img.size) # type: ignore

这里是不需要 ignore 的,而

... print(type(img), img.shape)

这里需要 ~

主要是因为 Tensor, PILImage, ndarray 都有 size 属性,但是 PILImage 没有 shape ,所以 mypy 检查的时候取类型中属性集合的交集就报错了~

mypy 会检查无用的 ignore,所以报错了 <string>:42: error: Unused "type: ignore" comment [unused-ignore]

@enkilee
Copy link
Contributor Author

enkilee commented Jul 1, 2024

收到,谢谢解惑。

python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
python/paddle/vision/datasets/folder.py Outdated Show resolved Hide resolved
@SigureMo
Copy link
Member

SigureMo commented Jul 4, 2024

CI 报错得看看

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 9d25d4a into PaddlePaddle:develop Jul 6, 2024
31 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