I’m using JetPack 4.1.1 DVP on a Xavier board running TensorRT 5.0.0
A TF model I’m trying to integrate in TensorRT requires the missing “_OneHot” operation. I have written a plugin to implement it but I cannot get it to work and it ends up failing at the “Formats and tactics selection” step:
../builder/cudnnBuilder2.cpp:795: virtual std::vector<nvinfer1::query::RequirementsCombination> nvinfer1::builder::EngineTacticSupply::getSupportedFormats(const nvinfer1::builder::Node&, const nvinfer1::query::Ports<nvinfer1::query::AbstractTensor>&): Assertion `!formats.empty()' failed.
I created a simple TensorFlow model using a OneHot operation as follows:
import uff
import numpy as np
import tensorflow as tf
DEPTH = 10
ON_VALUE = 1.0
OFF_VALUE = -1.0
x = np.array([[11, 0, 3, 4, 7, 3, 8, 10, 5, 4, 6, 5]])
input = tf.placeholder(tf.int32, shape=x.shape, name='input')
onehot = tf.one_hot(input, DEPTH, on_value=ON_VALUE, off_value=OFF_VALUE, name='output')
with tf.Session() as sess:
out = sess.run(onehot, feed_dict = {input: x})
print(out)
g = tf.get_default_graph()
print(g.get_operations())
uff_model = uff.from_tensorflow(
tf.get_default_graph(),
output_nodes=['output'],
output_filename='../data/model-onehot.uff',
text=False,
)
It generates the model and creates the “model-onehot.uff’” file properly. I then try to load it in a program using the UFF parser as follows:
static const int INPUT_LENGTH = 12;
static int32_t input[INPUT_LENGTH] = {
9, 0, 3, 4, 7, 3, 8, 2, 1, 4, 6, 5
};
int main(...)
{
IRuntime *runtime = nvinfer1::createInferRuntime(gLogger);
IBuilder* builder = nvinfer1::createInferBuilder(gLogger);
INetworkDefinition* network = builder->createNetwork();
auto parser = nvuffparser::createUffParser();
// parse UFF model
parser->setPluginFactory(&pluginFactory);
parser->registerInput("input", Dims2(1, INPUT_LENGTH), UffInputOrder::kNC);
parser->registerOutput("output");
parser->parse(MODEL_FILENAME, *network, nvinfer1::DataType::kFLOAT);
// configure and build engine
builder->setMaxBatchSize(1);
builder->setMaxWorkspaceSize(1 << 30);
ICudaEngine* engine = builder->buildCudaEngine(*network);
...
When doing so, the program crashes when calling "buildCudaEngine"by outputting the error message above. The OneHot plugin I wrote is mostly empty for now:
OneHotLayer::OneHotLayer() {
}
OneHotLayer::OneHotLayer(const void* buffer, size_t size) {
}
OneHotLayer::OneHotLayer(const Weights* weights, int nbWeights) {
assert(weights[0].type == DataType::kINT32);
assert(weights[0].count == 1);
mDepth = *(reinterpret_cast<const int32_t*>(weights[0].values));
assert(weights[1].type == DataType::kFLOAT);
assert(weights[1].count == 1);
mOnValue = *(reinterpret_cast<const float*>(weights[1].values));
assert(weights[2].type == DataType::kFLOAT);
assert(weights[2].count == 1);
mOffValue = *(reinterpret_cast<const float*>(weights[2].values));
}
Dims OneHotLayer::getOutputDimensions(int index, const Dims* inputs, int nbInputDims) {
assert((nbInputDims > 0) && (inputs[0].nbDims == 2));
return Dims3(inputs[0].d[0], inputs[0].d[1], mDepth);
}
int OneHotLayer::initialize() {
return 0;
}
int OneHotLayer::enqueue(int batchSize, const void* const *inputs, void** outputs, void *workspace,
cudaStream_t stream) {
return 0;
}
size_t OneHotLayer::getSerializationSize() {
return 0;
}
void OneHotLayer::serialize(void* buffer) {
}
void OneHotLayer::configure(const Dims* inputs, int nbInputs, const Dims* outputs, int nbOutputs,
int maxBatchSize) {
assert((nbInputs > 0) || (nbOutputs > 0));
mInputDim = Dims2(inputs[0].d[0], inputs[0].d[1]);
mOutputDim = Dims3(1, inputs[0].d[1], mDepth);
}
Please help, any feedback on what the error actually means would help. Thanks.