swoole / phpy

Connecting the Python and PHP ecosystems together
Apache License 2.0
542 stars 44 forks source link

PyCore::fn改了参数的类型 #18

Closed he426100 closed 11 months ago

he426100 commented 11 months ago

复现代码

<?php

$pycore = <<<CODE
from modelscope.utils.config import Config

cfg = Config.from_string('''
{
    "framework": "pytorch",
    "task": "ocr-recognition"
}
''', file_format='.json')

def test_py():
    return print(type(cfg))

def test_php(cb):
    return cb(cfg)
CODE;

$globals = new PyDict;
PyCore::exec($pycore, $globals);

$globals['test_py']();
$globals['test_php'](PyCore::fn(function ($cfg) {
    PyCore::print(PyCore::type($cfg));
}));

执行结果

$ php test.php
2023-12-18 11:19:05,821 - modelscope - INFO - PyTorch version 2.0.1 Found.
2023-12-18 11:19:05,821 - modelscope - INFO - TensorFlow version 2.15.0.post1 Found.
2023-12-18 11:19:05,821 - modelscope - INFO - Loading ast index from /home/mrpzx/.cache/modelscope/ast_indexer
2023-12-18 11:19:05,861 - modelscope - INFO - Loading done! Current index file version is 1.10.0, with md5 238e3ec6956bd434f67275fea2be7f2b and a total number of 946 components indexed
<class 'modelscope.utils.config.Config'>
<class 'list'>

测试https://modelscope.cn/models/damo/cv_convnextTiny_ocr-recognition-licenseplate_damo/summary的训练部分时发现无法传参_cfg_modify_fn,php定义的_cfg_modify_fn拿到的cfg和返回的cfg均不符合python中定义的cfg类型