crnn
crnn copied to clipboard
Is there any way to convert ".t7" into hdf5 format?
Hi,
Thank you for writing this code.
I wanted to use a pre-trained model which is in .t7
format, Is there any way I can convert this into hdf5
format in order to use it in Keras.
Try pytorch, you can use the "load_lua" function to read the .t7 file and get a "hashable_uniq_dict", it has two tensor lists named parameters and bnVars. Each tensor in the lists contains the weights/biases/means/vars of a convolution/linear/lstm/batchnorm layer. I converted the pytorch-tensor into numpy type, guess it's also easy converting pytorch-tensor into hdf5 format.
Hello @hzli-ucas , can you provide the script that does this operation ? I didn't find load_lua in pytorch. Thanks in advance :)
Hi @MounirB , I think pytorch has removed it from its new version. But you can still find the original .py file by searching "read_lua_file" or "load_lua" within pytorch repository, there are some commits including the file. For example, this one: https://github.com/pytorch/pytorch/blob/c6529f4851bb8ac95f05d3f17dea178a0367aaee/torch/utils/serialization/read_lua_file.py Er... I don't know how to add a link, it seems you cannot link to the right page by clicking it? Try copy it to the address bar, if the link doesn't work.
Hello @hzli-ucas , I am getting this error :
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
When trying to load a t7 model
@MounirB I don't know, never run into this error. Maybe you can try inserting some code to figure out what's wrong? Like inserting print(f.read(4)) in line 571 or 570 to see if you can successfully read the opened file?