我有一个编码器和一个解码器模型(monodepth2)。我尝试使用将它们从 Pytorch 转换为 Keras Onnx2Keras,但是:
TF2.3),并将每一层的权重(numpy 数组,包括权重和偏差)从 Pytorch 复制到 Keras,无需任何修改。但事实证明,Onnx2Keras转换后的编码器和自建解码器都无法重现相同的结果。下面是交叉对比图,首先介绍一下Decoder的代码。
首先是核心层,所有的 conv2d 层(Conv3x3, ConvBlock)都是基于此,但是不同的 dims 或者添加一个激活:
# Conv3x3 (normal conv2d without BN nor activation)
# There's also a ConvBlock, which is just "Conv3x3 + ELU activation", so I don't list it here.
def TF_Conv3x3(input_channel, filter_num, pad_mode='reflect', activate_type=None):
# Actually it's 'reflect, but I implement it with tf.pad() outside this
padding = 'valid' …Run Code Online (Sandbox Code Playgroud) 我尝试创建一个解码器,它采用五张量元组作为输入。当我保存它时,.h5它工作正常,但当我尝试保存(无错误报告)、加载和进行推理时,它报告:
Traceback (most recent call last):
File "D:/MA/Recources/monodepth2-torch/dsy.py", line 196, in <module>
build_model(inputs)
File "D:/MA/Recources/monodepth2-torch/dsy.py", line 185, in build_model
outputs = decoder_pb(inputs)
File "C:\Users\Dexxh\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\function.py", line 1655, in __call__
return self._call_impl(args, kwargs)
File "C:\Users\Dexxh\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\function.py", line 1673, in _call_impl
return self._call_with_flat_signature(args, kwargs, cancellation_manager)
File "C:\Users\Dexxh\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\function.py", line 1695, in _call_with_flat_signature
len(args)))
TypeError: signature_wrapper(input_1, input_2, input_3, input_4, input_5) takes 0 positional arguments but 1 were given
Run Code Online (Sandbox Code Playgroud)
我对模型的定义如下。细节看起来没有问题,因为当我将其加载为 Keras 模型时,它运行良好。我会tensorflow 2.3.1在你需要的时候使用。
class DepthDecoder(tf.keras.Model):
def __init__(self):
super(DepthDecoder, self).__init__()
self.num_ch_enc = [64, 64, …Run Code Online (Sandbox Code Playgroud) 这是代码。我试图通过使用给这个参数“False”值
python file.py --add_depth_loss False
Run Code Online (Sandbox Code Playgroud)
但它仍然打印“True”......这是为什么?
from absl import flags, app
FLAGS = flags.FLAGS
flags.DEFINE_boolean('add_depth_loss', None, 'sss')
flags.mark_flag_as_required('add_depth_loss')
def main(_):
print(FLAGS.add_depth_loss)
if __name__ == '__main__':
app.run(main)
Run Code Online (Sandbox Code Playgroud)