def convert_to_caffe(self, name): caffe_net = caffe.NetSpec() layer = L.Input(shape=dict(dim=[1, 3, args.image_hw, args.image_hw])) caffe_net.tops['data'] = layer slim.generate_caffe_prototxt(self, caffe_net, layer) print(caffe_net.to_proto()) with open(name + '.prototxt', 'wb') as f: f.write(str(caffe_net.to_proto()).encode()) caffe_net = caffe.Net(name + '.prototxt', caffe.TEST) slim.convert_pytorch_to_caffe(self, caffe_net) caffe_net.save(name + '.caffemodel')
def generate_caffe_prototxt(self, caffe_net, layer): if self.stride == 1: layer_x1, layer_x2 = L.Slice(layer, ntop=2, axis=1, slice_point=[self.in_channels // 2]) caffe_net[self.g_name + '/slice1'] = layer_x1 caffe_net[self.g_name + '/slice2'] = layer_x2 layer_x2 = slim.generate_caffe_prototxt(self.conv, caffe_net, layer_x2) else: layer_x1 = slim.generate_caffe_prototxt(self.conv0, caffe_net, layer) layer_x2 = slim.generate_caffe_prototxt(self.conv, caffe_net, layer) layer = L.Concat(layer_x1, layer_x2, axis=1) caffe_net[self.g_name + '/concat'] = layer layer = slim.generate_caffe_prototxt(self.shuffle, caffe_net, layer) return layer
def generate_caffe_prototxt(self, caffe_net, layer): data_layer = layer network = slim.generate_caffe_prototxt(self.network, caffe_net, data_layer) return network