tensorlayer / TensorLayerX

TensorLayerX: A Unified Deep Learning and Reinforcement Learning Framework for All Hardwares, Backends and OS.
Other
538 stars 45 forks source link

Support of tlx for nested structure network #29

Open qiutzh opened 2 years ago

qiutzh commented 2 years ago

New Issue Checklist

Issue Description

请问,tensorlayerx 目前支持 paddle 做后端,然后运行包含嵌套结构关系的网络模型吗?我运行 tlx 提供的 example 例子,发现 nested_usage_of_layer.py 这个文件以 tf 做后端可以运行,但改成 paddle 做后端,会提示报错,错误提示:

Traceback (most recent call last):
  File "D:/ProjectByPython/code/reference/DL_Platform/TensorLayer/TensorLayerX-0.5.6/examples/basic_tutorials/nested_usage_of_layer.py", line 159, in <module>
    grad = tape.gradient(_loss_ce, train_weights)
  File "D:\Software\miniconda3\envs\py37env_tlx\lib\site-packages\tensorflow_core\python\eager\backprop.py", line 984, in gradient
    if not t.dtype.is_floating:
AttributeError: 'paddle.fluid.core_avx.VarType' object has no attribute 'is_floating'

Reproducible Code

python: 3.7 paddlepaddle version: 2.3.0 tensorlayerx version: 0.5.6

代码就是例子中的 nested_usage_of_layer.py 这个文件。 nested_usage_of_layer.txt

自己在转换其它存在嵌套关系的网络模型时,如 resnet 时,发现以 paddle 做后端也可以成功运行,但是结果不准确,BatchNorm2d 这一层开始的输出就不再一样了。

Laicheng0830 commented 2 years ago

这个报错是正常的,nested_usage_of_layer.py 的代码是混合TF运行的,其中用到了tf.GradientTape()。

Laicheng0830 commented 2 years ago

qiutzh结果不准确能给个github仓链接吗,或者贴例子

qiutzh commented 1 year ago

@Laicheng0830 忘记回复您了,抱歉,嵌套结构的网络定义tensorlayerx也是支持的~