从pytorch到onnx到张量流图定义到tflite的转换-TOCO失败-类型检查失败

时间:2018-11-16 15:22:18

标签: python tensorflow conv-neural-network pytorch onnx

我有一个简单的网络,该网络由两个卷积层和一个完全连接的层组成,这些层在pytorch中定义如下:

def __init__([...])
    [...]
    self.conv1 = nn.Conv1d(1, channels_conv1, width_conv1)
    self.conv2 = nn.Conv1d(channels_conv1, channels_conv2, width_conv2)
    self.fc1 = nn.Linear(hidden_layer_size, 2)

def forward(self, x):
    x = functional.max_pool1d(functional.relu(self.conv1(x)), 2, stride=2)
    x = functional.max_pool1d(functional.relu(self.conv2(x)), 2, stride=2)
    x = x.view(-1, self.num_flat_features(x))
    x = functional.softmax(self.fc1(x))
    return x

我想将其转换为tflite。因此,首先将其转换为onnx

torch.onnx.export(model, input, "net.onnx",
                  export_params=True,
                  input_names=['input'],
                  output_names=['output'],
                  verbose=true)

然后我用onnx-tf将结果转换为张量流图定义。产生的net.pb没问题,因为它产生的输出与带有prepare(onnx.load('net.onnx')).run(...)的原始输出相同。

但是,我有两个问题:一个较小的问题是net.pb图不再包含输出节点,因此我必须寻找输出节点。 第二个是当我尝试使用

执行最终转换时
tflite_convert --output_file=net.tflite --graph_def_file=net.pb --input_arrays=input --output_arrays=Softmax

在类型检查中出现TOCO失败:

tensorflow.lite.python.convert.ConverterError: TOCO failed. See console for info.
2018-11-16 16:11:37.592030: I tensorflow/lite/toco/import_tensorflow.cc:1280] Converting unsupported operation: Where
2018-11-16 16:11:37.601384: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 61 operators, 113 arrays (0 quantized)
2018-11-16 16:11:37.602005: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 61 operators, 113 arrays (0 quantized)
2018-11-16 16:11:37.602311: F tensorflow/lite/toco/graph_transformations/resolve_constant_gather.cc:105] Check failed: coords_array.data_type == ArrayDataType::kInt32 Only int32 indices are supported
Aborted (core dumped)

我尝试在网络中进行挖掘,但是似乎找不到令人烦恼的对象,也没有发现明显与此问题相关的问题。任何指向此过程可能会脱轨的指针的方法都很棒!

tf-nightly==1.13.0.dev20181116
onnx==1.3.0
torch-nightly==1.0.0.dev201811

onnx-tensorflow中的master(提交b5fef1b

0 个答案:

没有答案
相关问题