facebookarchive / caffe2

Caffe2 is a lightweight, modular, and scalable deep learning framework.
https://caffe2.ai
Apache License 2.0
8.42k stars 1.95k forks source link

How to create a model with only predict_net.pb? #510

Open nicklhy opened 7 years ago

nicklhy commented 7 years ago

I translated some models from caffe, i.e. alexnet. Now, I want to create and initialize the model randomly in caffe2(without using the pre-trained weights). How can I do that? Simply executing the code below will raise an error

net_def = caffe2_pb2.NetDef()
with open('alexnet.pb', 'r') as f:
    net_def.ParseFromString(f.read())
    net_def.device_option.CopyFrom(device_opts)
workspace.CreateNet(net_def)
'''
RuntimeError: [enforce fail at operator.cc:26] blob != nullptr. op Conv: Encountered a non-existing input blob: data
'''
KeyKy commented 7 years ago

In my opinion, you can run it in caffe.Net(prototxt, caffe.TEST) and then save the caffemodel using net.save. Finally, translate it to caffe2

nicklhy commented 7 years ago

@KeyKy , this works but looks rather ugly. What if I do not have caffe in my system? Why do I have to save such useless random weights in disk (for every network structure I would like to use)? I just want to randomly initialize all parameters on-the-fly. I think it should not be any difficult to create all the blobs as long as we have the network definition file.

szbach commented 6 years ago

try to use FeedBlob before createnet...