将火炬t7型号转换为keras h5

问题描述 投票:0回答:1

我们如何将t7模型转换为keras'h5?我正在尝试为c3d-sports1m-kinetics.t7这样做,你可以在这里找到https://github.com/kenshohara/3D-ResNets/releases

至少我可以要求的是一种方法将t7模型加载到python(pytorch)然后提取它的权重,但我不能用load_lua()函数来做...

尝试使用此函数https://github.com/pytorch/pytorch/blob/c6529f4851bb8ac95f05d3f17dea178a0367aaee/torch/utils/serialization/read_lua_file.py时出错

我得到的错误如下:

Traceback (most recent call last):
File "convert_t7_to_hdf5.py", line 574, in <module>
    a = load_lua("model.t7")
  File "convert_t7_to_hdf5.py", line 571, in load_lua
    return reader.read()
  File "convert_t7_to_hdf5.py", line 542, in read
    typeidx = self.read_int()
  File "convert_t7_to_hdf5.py", line 440, in read_int
    return self._read('i')
  File "convert_t7_to_hdf5.py", line 431, in _read
    result = struct.unpack(fmt, self.f.read(sz))
ValueError: read of closed file
lua keras pytorch torch
1个回答
1
投票

如此链接所述,https://github.com/pytorch/pytorch/issues/15307#issuecomment-448086741

使用torchfile包,加载成功。您可以将模型的内容转储到文件中,然后了解内容。每个层信息都存储为字典。了解模型体系结构可以更容易地解析内容。

>>> import torchfile
>>> model = torchfile.load('c3d-sports1m-kinetics.t7')
>>> module = model.modules[0].modules[0]
>>> module.name
b'conv1a'
>>> module['weight'].shape
(64, 3, 3, 3, 3)
>>> module['bias'].shape
(64,)
© www.soinside.com 2019 - 2024. All rights reserved.