Hi,
I am sorry about that I would like to clarify some questions, even I knew that these are quite basic questions.
However, I am really confused about the part of building prepare_namespace_plugin_map and ModelData for the uff_custom_plugin of python sample.
In the lenet5.py, one part of original code is
def build_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.InputLayer(input_shape=[1, 28, 28], name="InputLayer"))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(512))
model.add(tf.keras.layers.Activation(activation=tf.nn.relu6, name="ReLU6"))
model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax, name="OutputLayer"))
return model
Because ReLU6 operation is not supported by TensorRT, we need to create it.
In the sample.py,
class ModelData(object):
INPUT_NAME = "InputLayer"
INPUT_SHAPE = (MNIST_CHANNELS, MNIST_IMAGE_SIZE, MNIST_IMAGE_SIZE)
RELU6_NAME = "ReLU6"
OUTPUT_NAME = "OutputLayer/Softmax"
OUTPUT_SHAPE = (MNIST_IMAGE_SIZE, )
DATA_TYPE = trt.float32
def prepare_namespace_plugin_map():
trt_relu6 = gs.create_plugin_node(name="trt_relu6", op="CustomClipPlugin", clipMin=0.0, clipMax=6.0)
namespace_plugin_map = {
ModelData.RELU6_NAME: trt_relu6
}
return namespace_plugin_map
I showed the results below that what I did some tests before.
If I modify the name of relu6 to the name of relu6_1, I must need to modify the RELU6_NAME of ModelData area. Then it works well.
def build_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.InputLayer(input_shape=[1, 28, 28], name="InputLayer"))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(512))
model.add(tf.keras.layers.Activation(activation=tf.nn.relu6, name="ReLU6_1"))
model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax, name="OutputLayer"))
return model
class ModelData(object):
INPUT_NAME = "InputLayer"
INPUT_SHAPE = (MNIST_CHANNELS, MNIST_IMAGE_SIZE, MNIST_IMAGE_SIZE)
RELU6_NAME = "ReLU6_1"
OUTPUT_NAME = "OutputLayer/Softmax"
OUTPUT_SHAPE = (MNIST_IMAGE_SIZE, )
DATA_TYPE = trt.float32
In this case, it is only one relu6. So now supposes that there are two or over two relu6 in the neural network, and I also named those relu6 being different names.
def build_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.InputLayer(input_shape=[1, 28, 28], name="InputLayer"))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(512))
model.add(tf.keras.layers.Activation(activation=tf.nn.relu6, name="ReLU6"))
model.add(tf.keras.layers.Dense(512))
model.add(tf.keras.layers.Activation(activation=tf.nn.relu6, name="ReLU6_1"))
model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax, name="OutputLayer"))
return model
one is ReLU6, and the other is ReLU6_1.
How can I correctly set the parameters in the ModelData and prepare_namespace_plugin_map?
As my thought, I will add the second ReLU6_1 in the ModelData and namespace_plugin_map.
class ModelData(object):
INPUT_NAME = "InputLayer"
INPUT_SHAPE = (MNIST_CHANNELS, MNIST_IMAGE_SIZE, MNIST_IMAGE_SIZE)
[b] RELU6_NAME = "ReLU6"
RELU6_1_NAME = "ReLU6_1"[/b]
OUTPUT_NAME = "OutputLayer/Softmax"
OUTPUT_SHAPE = (MNIST_IMAGE_SIZE, )
DATA_TYPE = trt.float32
Although it showed that it works well, I don’t know whether it is real or not.
Because probably it only works for first one ReLU6, not works for second one.
My questions are
- Should I need to add the ModelData.RELU6_1_NAME in the namespace_plugin_map? such as
```
namespace_plugin_map = {
ModelData.RELU6_NAME: trt_relu6,
ModelData.RELU6_1_NAME: trt_relu6
}
```
I tried it before, but I got this error.
[TensorRT] ERROR: UffParser: Graph error: Cycle graph detected [TensorRT] ERROR: Network must have at least one output [TensorRT] ERROR: Network validation failed. Traceback (most recent call last): File "sample.py", line 208, in <module> main() File "sample.py", line 196, in main with build_engine(MODEL_PATH) as engine: AttributeError: __enter__
I am confused here…
How can I correct it? -
suppose today we need to add each of relu6 in the ModelData, and then if there are 50 relu6 in a neural network, should we really need to list all names of relu6 in the ModelData?
For example,
class ModelData(object): INPUT_NAME = "InputLayer" INPUT_SHAPE = (MNIST_CHANNELS, MNIST_IMAGE_SIZE, MNIST_IMAGE_SIZE) [b] RELU6_NAME = "ReLU6" RELU6_1_NAME = "ReLU6_1" RELU6_2_NAME = "ReLU6_2" RELU6_3_NAME = "ReLU6_3" RELU6_4_NAME = "ReLU6_4" . . . RELU6_49_NAME = "ReLU6_49"[/b] OUTPUT_NAME = "OutputLayer/Softmax" OUTPUT_SHAPE = (MNIST_IMAGE_SIZE, ) DATA_TYPE = trt.float32
However, I don’t think so that it is using this way…
I got stuck in this part for many days that I want to convert .pb to uff…
Can you give me some advice or help?
Thank you very much!!