我有一个简单的网络,由两个卷积层和一个完全连接的网络组成,在 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)
然后我将结果转换为 tensorflow 图定义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-tensorflowmaster
的(commit b5fef1b
)