Преобразование Caffe в Caffe2

Я пытаюсь сделать прогноз для модели caffe2, конвертировать из caffe, используя скрипт, включенный в caffe2. Скрипт завершается корректно, давая мне "init_net.pb" и "Предсказание_нет.пб".

Когда я пытаюсь вызвать метод Predictor run() Я получаю следующее сообщение об ошибке:

Traceback (most recent call last):
  File "caffe2Inference.py", line 23, in <module>
    results = p.run(input)
RuntimeError: [enforce fail at conv_op_impl.h:21] X.ndim() == filter.ndim(). 3 vs 4 Error from operator: 
input: "data" input: "conv1/time_w" input: "conv1/time_b" output: "conv1/time" type: "Conv" arg { name: "stride" i: 1 } arg { name: "pad" i: 0 } arg { name: "kernel_h" i: 7 } arg { name: "kernel_w" i: 1 }

Это мой код для выполнения вывода:

# load up the caffe2 workspace
from caffe2.python import workspace, core
import numpy as np

# helper image processing functions
#import caffe2.python.tutorials.helpers as helpers
name= "scnn+fc/"
INIT_NET = name+"/init_net.pb"
PREDICT_NET = name+"/predict_net.pb"
#read protobuf
with open(INIT_NET,"rb") as f:
    init_net = f.read()
with open(PREDICT_NET,"rb") as f:
    predict_net = f.read()

# you must name it something
workspace.RunNetOnce(init_net)
workspace.CreateNet(predict_net)
p = workspace.Predictor(init_net, predict_net)

input = np.ones((1,1,63,13))
# submit the image to net and get a tensor of results
results = p.run(input)
res= np.asarray(results)
#response = helpers.parseResults(results)
# and lookup our result from the list

И это мой оригинальный.prototxt

name: "UNIPINET"
#input:"data"
#input_shape: { dim: 1 dim: 1 dim: 63 dim: 13 } 
layer { name: "data" 
type: "Input" 
top: "data" 
input_param
{ 
  shape 
  {
    dim: 1 
    dim: 3 
    dim: 224 
    dim: 224 
   } 
  } 
}
layer {
  name: "conv1/time"
  type: "Convolution"
  bottom: "data"
  top: "conv1/time"
  convolution_param {
    num_output: 1
    bias_term: true
    kernel_h: 7 
    kernel_w: 1
    #engine: CAFFE
    stride: 1
  }
}

layer {
  name: "conv1/freq"
  type: "Convolution"
  bottom: "conv1/time"
  top: "conv1/freq"
  convolution_param {
    num_output: 32
    bias_term: true
    kernel_h:1
    kernel_w:3
    stride: 1
  }
}
layer {
  name: "conv1/freq/bn"
  type: "BatchNorm"
  bottom: "conv1/freq"
  top: "conv1/freq/bn"
}
layer {
  name: "conv1/freq/bn/scale"
  type: "Scale"
  bottom: "conv1/freq/bn"
  top: "conv1/freq/bn/scale"
  scale_param{
    bias_term: true
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1/freq/bn/scale"
  top: "relu1"
}
layer {
  name: "conv2/time"
  type: "Convolution"
  bottom: "relu1"
  top: "conv2/time"
  convolution_param {
    num_output: 32
    bias_term: true
    kernel_h: 15
      kernel_w: 1
    pad_h:7
    #engine: CAFFE
    stride: 1
  }
}

layer {
  name: "conv2/freq"
  type: "Convolution"
  bottom: "conv2/time"
  top: "conv2/freq"
  convolution_param {
    num_output: 32
    bias_term: true
    kernel_h:1
      kernel_w:3
    pad_w:1
    stride: 1
  }
}
layer {
  name: "conv2/freq/bn"
  type: "BatchNorm"
  bottom: "conv2/freq"
  top: "conv2/freq/bn"
}
layer {
  name: "conv2/freq/bn/scale"
  type: "Scale"
  bottom: "conv2/freq/bn"
  top: "conv2/freq/bn/scale"
  scale_param{
    bias_term: true
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2/freq/bn/scale"
  top: "relu2"
}
layer {
  name: "conv3/time"
  type: "Convolution"
  bottom: "relu2"
  top: "conv3/time"
  convolution_param {
    num_output: 32
    bias_term: true
    kernel_h: 13
      kernel_w: 1
    pad_h:6
    #engine: CAFFE
    stride: 1
  }
}

layer {
  name: "conv3/freq"
  type: "Convolution"
  bottom: "conv3/time"
  top: "conv3/freq"
  convolution_param {
    num_output: 128
    bias_term: true
    kernel_h:1
      kernel_w:3
    pad_w:1
    stride: 1
  }
}
layer {
  name: "conv3/freq/bn"
  type: "BatchNorm"
  bottom: "conv3/freq"
  top: "conv3/freq/bn"
}
layer {
  name: "conv3/freq/bn/scale"
  type: "Scale"
  bottom: "conv3/freq/bn"
  top: "conv3/freq/bn/scale"
  scale_param{
    bias_term: true
  }
}
layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3/freq/bn/scale"
  top: "relu3"
}

layer {
  name: "avg_pool"
  type: "Pooling"
  bottom: "relu3"
  top: "avg_pool"
  pooling_param {
    pool: MAX
    global_pooling: true
  }
}
layer {
  name: "fc"
  type: "InnerProduct"
  bottom: "avg_pool"
  top: "fc"
  inner_product_param {
    num_output: 12
  }
}

layer {
  name: "output"
  type: "Softmax"
  bottom: "fc"
  top: "output"
}

1 ответ

p.run Ожидаемый тип - это список входных данных.

Изменить:

p.run(input)

От:

p.run([input.astype(np.float32)])
Другие вопросы по тегам