-
Notifications
You must be signed in to change notification settings - Fork 15
Custom Model
To use a custom model, such as the one used in the Redtail project, simply use post_proc:=None
. In this case the node will just publish the raw output of the DNN (e.g. softmax layer) using standard Image messages.
- for
1D
output like that of the softmax layer, the dimensions of the published image are1x1xC
whereC
is the size of the layer (e.g. 6 for the TrailNetout
layer or 1000 for ImageNet'ssoftmax
layer). - The
encoding
field of the message is in the following format:32FCXXX
whereXXX
is equal to number of channels. For example, for TrailNet:32FC6
, for ImageNet:32FC1000
.32
means 32-bit andF
means float. See the ROS documentation for more details. - The
data
field contains the output of the DNN in byte array representation so it should be cast to a 32-bit float type.
The default topic name is /caffe_ros/network/output
but it can be changed using launch file or command line.
The node requires two parameters:
-
prototxt_path
- path to the Caffe model .prototxt file -
model_path
- path to the Caffe model binary file Additionally, make sure that other parameters, like the input/output layer names (input_layer
/output_layer
) are set correctly. An example of the command line for TrailNet:
rosrun caffe_ros caffe_ros_node __name:=trails_dnn _prototxt_path:=/data/src/redtail/models/pretrained/TrailNet_SResNet-18.prototxt _model_path:=/data/src/redtail/models/pretrained/TrailNet_SResNet-18.caffemodel _output_layer:=out
Note: when using rosrun
remember to prefix parameters with _
(__
for system parameters) and use :=
when assigning a value.
To check that the DNN node is producing some data, make sure that camera node (a real camera via gscam
or an image_pub
node) is running, and execute rostopic echo /trails_dnn/network/output
. An example of the output:
header:
seq: 201
stamp:
secs: 1501106944
nsecs: 796543294
frame_id: ''
height: 1
width: 1
encoding: 32FC6
is_bigendian: 0
step: 24
data: [110, 74, 230, 58, 135, 125, 95, 60, 228, 14, 124, 63, 133, 26, 6, 61, 156, 75, 115, 63, 91, 87, 138, 60]
To convert the data
byte array to float array, use this simple Python script:
import struct
data = bytearray([110, 74, 230, 58, 135, 125, 95, 60, 228, 14, 124, 63, 133, 26, 6, 61, 156, 75, 115, 63, 91, 87, 138, 60])
print(struct.unpack('<%df' % (len(data) / 4), data))