将 torch t7 模型转换为 keras h5

我们如何将 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
点赞
用户5597718
用户5597718

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

通过_torchfile_包的使用,加载成功。您可以将 model 的内容转储到文件中,然后理解其内容。每一层的信息都储存为一个字典。知道模型架构将使分析其内容更加容易。

>>> 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,)
2019-03-13 17:54:41