How to load trained caffe model in h5 format to c++caffe net?

763 views
Skip to first unread message

Nyan Naing

unread,
Feb 20, 2017, 2:27:08 AM2/20/17
to Caffe Users

Normally trained caffe model are in .caffemodel extension and actually they are in binary protobuf format.


Any idea how to load a caffe model in hdf5 format to caffe net in c++?


I have a model trained with python caffe in hdf5 format.


My application is in c++ using caffe c++ version and I prefer to use c++ than python.


How to read the model in caffe trained model in hdf5 format to c++ caffe net?


I know that caffe has hdf5data layer inside. Is there a sample program for that?


I found CopyTrainedLayersFromHDF5(string) API in net.hpp file.


When I load .h5 model using that API, I have error as


HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 140737353775552:
 
#000: ../../../src/H5G.c line 463 in H5Gopen2(): unable to open group
    major
: Symbol table
    minor
: Can't open object
  #001: ../../../src/H5Gint.c line 320 in H5G__open_name(): group not found
    major: Symbol table
    minor: Object not found
  #002: ../../../src/H5Gloc.c line 430 in H5G_loc_find(): can'
t find object
    major
: Symbol table
    minor
: Object not found
 
#003: ../../../src/H5Gtraverse.c line 861 in H5G_traverse(): internal path traversal failed
    major
: Symbol table
    minor
: Object not found
 
#004: ../../../src/H5Gtraverse.c line 641 in H5G_traverse_real(): traversal operator failed
    major
: Symbol table
    minor
: Callback failed
 
#005: ../../../src/H5Gloc.c line 385 in H5G_loc_find_cb(): object 'data' doesn't exist
    major
: Symbol table
    minor
: Object not found
F0220
15:26:05.044219 24529 net.cpp:811] Check failed: data_hid >= 0 (-1 vs. 0) Error reading weights from data_800000.h5
*** Check failure stack trace: ***
   
@     0x7ffff64afdcd  google::LogMessage::Fail()
   
@     0x7ffff64b1d08  google::LogMessage::SendToLog()
   
@     0x7ffff64af963  google::LogMessage::Flush()
   
@     0x7ffff64b263e  google::LogMessageFatal::~LogMessageFatal()
   
@     0x7ffff691c3a3  caffe::Net<>::CopyTrainedLayersFromHDF5()
   
@           0x40828d  ExtractFeature::ExtractFeature()
   
@           0x40ce78  main
   
@     0x7ffff5bf8f45  __libc_start_main
   
@           0x4080c9  (unknown)

Program received signal SIGABRT, Aborted.
0x00007ffff5c0dc37 in __GI_raise (sig=sig@entry=6)
    at
../nptl/sysdeps/unix/sysv/linux/raise.c:56
56    ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.


Shai Bagon

unread,
Feb 23, 2017, 5:10:19 AM2/23/17
to Caffe Users
solution was found on stackoverflow
Reply all
Reply to author
Forward
0 new messages