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

Add paddle hub #31873

Merged
merged 38 commits into from
Apr 25, 2021
Merged

Add paddle hub #31873

merged 38 commits into from
Apr 25, 2021

Conversation

lyuwenyu
Copy link
Contributor

PR types

New features

PR changes

Others

Describe

  • Usage:
import paddle.hub as hub

if __name__ == '__main__':

    models = hub.list('lyuwenyu/PaddleClas:hub_L', force_reload=False)
    print(len(models))
    
    # print(hub.list('/Users/lvwenyu01/.cache/paddle/hub/lyuwenyu_PaddleClas_hub_L', source='local'))
    doc = hub.help('lyuwenyu/PaddleClas:hub_L', model='ResNet18')
    print(doc)

    model = hub.load('lyuwenyu/PaddleClas:hub_L', model='MobileNetV3_large_x0_35', source='github', pretrained=True)
    # print(model)
    # print(type(model))


@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@lyuwenyu lyuwenyu changed the title Hub l add paddle Hub Mar 26, 2021
@lyuwenyu lyuwenyu closed this Mar 26, 2021
@lyuwenyu lyuwenyu reopened this Mar 26, 2021
@lyuwenyu lyuwenyu closed this Mar 26, 2021
@lyuwenyu lyuwenyu reopened this Mar 26, 2021
@lyuwenyu lyuwenyu changed the title add paddle Hub Add paddle hub Mar 31, 2021
```python
import paddle

paddle.hub.help('lyuwenyu/PaddleClas:hub_L', source='github', force_reload=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

using official repo will be better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good. It's testing code, beacuse PaddleCls dont have hub.conf by now.

@LielinJiang
Copy link
Contributor

Need a simple unittest

Load model

Args:
repo_dir(str): github or local path
Copy link
Contributor

Choose a reason for hiding this comment

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

as offline discussion, also can add gitee

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, will push it after testing offline

ZeyuChen
ZeyuChen previously approved these changes Apr 22, 2021
Copy link
Member

@ZeyuChen ZeyuChen left a comment

Choose a reason for hiding this comment

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

LGTM

repo_dir, force_reload, True, source=source)

sys.path.insert(0, repo_dir)
hub_module = __import__(MODULE_HUBCONF.split('.')[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that sys.modules['hubconf'] will be used by default on the second load, which will causes unexpected behavior.

Copy link
Contributor Author

@lyuwenyu lyuwenyu Apr 22, 2021

Choose a reason for hiding this comment

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

You are right. I should pop it after __import__ module to keep sys.module clean

sys.modules.pop('hubconf')

ps. using importlib seems beeter, but it‘s incompatible in py2 and py3 😢

# Setup hub_dir to save downloaded files
hub_dir = HUB_DIR
if not os.path.exists(hub_dir):
os.makedirs(hub_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that multi-process calls may cause the problem of repeated directory creation and raise an exception.

suggest:

os.makedirs(hub_dir, exist_ok=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy~

func = getattr(m, name, None)

if func is None or not callable(func):
raise RuntimeError('Canot find callable {} in hubconf'.format(name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Canot -> Cannot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy~

Args:
repo_dir(str): github or local path
github path (str): a str with format "repo_owner/repo_name[:tag_name]" with an optional
tag/branch. The default branch is `master` if not specified.
Copy link
Contributor

Choose a reason for hiding this comment

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

default是main还是master
MASTER_BRANCH定义是main

Copy link
Contributor Author

Choose a reason for hiding this comment

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

应该是main, 我修改下

```python
import paddle

paddle.hub.help('lyuwenyu/paddlehub_demo:main', source='github', force_reload=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

示例的api不对

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it ~😢

Args:
repo_dir(str): github or local path
github path (str): a str with format "repo_owner/repo_name[:tag_name]" with an optional
tag/branch. The default branch is `master` if not specified.
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

Args:
repo_dir(str): github or local path
github path (str): a str with format "repo_owner/repo_name[:tag_name]" with an optional
tag/branch. The default branch is `master` if not specified.
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

github path (str): a str with format "repo_owner/repo_name[:tag_name]" with an optional
tag/branch. The default branch is `master` if not specified.
local path (str): local repo path
mdoel (str): model name
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

np.testing.assert_equal(out.shape, [1, 8, 50, 50])

model = hub.load(
self.github_repo, model='MM', source='github', force_reload=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

是否能检查下load之后的结果是否正确?
这几个参数是否发挥作用,这个用例并不能很好的测试出来。

Copy link
Contributor Author

@lyuwenyu lyuwenyu Apr 23, 2021

Choose a reason for hiding this comment

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

  1. 已修改, 增加固定输入和pretrained参数并测试输出的正确性
  2. 这几个参数是否发挥作用,是的 一个用例不能很好的反馈出来 但是结合上下文多个tests按顺序是隐式的 1. hub.load source local和remote模型使用的地址不一致,2. 首次使用remote时候本地是没有缓存的 当为False时候不会download数据 测试能过说明前边为True时候起作用了,3. 不符合要求的参数 在异常里测试的

docs = hub.help(
self.github_repo, model='MM', source='github', force_reload=False)

print(docs)
Copy link
Contributor

Choose a reason for hiding this comment

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

检查下docs的值是否正确?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯嗯可以

source='github',
force_reload=False, )

print(models)
Copy link
Contributor

Choose a reason for hiding this comment

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

检查下list的执行结果是否符合预期?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯嗯可以

@lyuwenyu lyuwenyu dismissed stale reviews from ZeyuChen, qingqing01, and XieYunshen via ae0bb17 April 23, 2021 02:46
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Apr 23, 2021
@PaddlePaddle PaddlePaddle unlocked this conversation Apr 23, 2021
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Apr 23, 2021
@PaddlePaddle PaddlePaddle unlocked this conversation Apr 23, 2021
XieYunshen
XieYunshen previously approved these changes Apr 23, 2021
@@ -19,7 +19,7 @@
import zipfile
from paddle.utils.download import get_path_from_url

MASTER_BRANCH = 'main'
MAIN_BRANCH = 'main'
Copy link
Contributor

Choose a reason for hiding this comment

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

变量名称是不是应该叫DEFAULT_BRANCH
另外,是不是github的时候default是main, gitee的时候default是master,比较合理。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea

XieYunshen
XieYunshen previously approved these changes Apr 25, 2021
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link

@saxon-zh saxon-zh left a comment

Choose a reason for hiding this comment

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

LGTM

@qingqing01 qingqing01 merged commit 4e460d7 into PaddlePaddle:develop Apr 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants