Showing results for 
Search instead for 
Did you mean: 

Bad porformance for custom trained faster rcnn using opvino

Jump to solution


I trained a faster rcnn model to detect cells from images using tensorflow api, resnet50, and the performance is quite well.


Than I converted the frozen_inference_graph.pb to frozen_inference_graph.xml, using model optimizer:

python "C:\\Program Files (x86)\\IntelSWTools\\openvino_2020.1.033\\deployment_tools\\model_optimizer\\" --input_model "F:\\data\\cellcounter\\FRCNN\\crop\\training\\frozen_inference_graph.pb" --input_shape [1,600,800,3] --tensorflow_object_detection_api_pipeline_config "F:\\data\cellcounter\\FRCNN\\crop\\training\\pipeline.config" --tensorflow_use_custom_operations_config "C:\\Program Files (x86)\\IntelSWTools\\openvino_2020.1.033\\deployment_tools\\model_optimizer\\extensions\\front\\tf\\faster_rcnn_support_api_v1.14.json" --output_dir="F:\data\cellcounter\FRCNN\crop"

However, the detecion results was really bad.


Does anyone know why? Appreciate it.


from __future__ import print_function
import sys
import os
from argparse import ArgumentParser, SUPPRESS
import cv2
import time
import logging as log

from openvino.inference_engine import IENetwork, IEPlugin

def build_argparser():
parser = ArgumentParser(add_help=False)
args = parser.add_argument_group('Options')
args.add_argument('-h', '--help', action='help', default=SUPPRESS, help='Show this help message and exit.')
args.add_argument("-m", "--model", help="Required. Path to an .xml file with a trained model.",
default='F:\\data\\cellcounter\\FRCNN\\crop\\frozen_inference_graph.xml', type=str)
args.add_argument("-i", "--input",
help="Required. Path to video file or image. 'cam' for capturing video stream from camera",
default='F:\\data\\cellcounter\\FRCNN\\crop\\labeled\\test\\191218-c2 (11).png', type=str)
args.add_argument("-l", "--cpu_extension",
help="Optional. Required for CPU custom layers. Absolute path to a shared library with the "
"kernels implementations.", type=str, default=None)
args.add_argument("-d", "--device",
help="Optional. Specify the target device to infer on; CPU, GPU, FPGA, HDDL or MYRIAD is "
"acceptable. The demo will look for a suitable plugin for device specified. "
"Default value is CPU", default="CPU", type=str)
args.add_argument("--labels", help="Optional. Path to labels mapping file", default='F:\\data\\cellcounter\\FRCNN\\crop\\label_map.pbtxt', type=str)
args.add_argument("-pt", "--prob_threshold", help="Optional. Probability threshold for detections filtering",
default=0.1, type=float)
args.add_argument("--no_show", help="Optional. Don't show output", action='store_true')

return parser

args = build_argparser().parse_args()
model_xml = args.model
model_bin = os.path.splitext(model_xml)[0] + ".bin"
net = IENetwork.from_ir(model=model_xml, weights=model_bin)
img_info_input_blob = None
feed_dict = {}
for blob_name in net.inputs:
if len(net.inputs[blob_name].shape) == 4:
input_blob = blob_name
elif len(net.inputs[blob_name].shape) == 2:
img_info_input_blob = blob_name
raise RuntimeError("Unsupported {}D input layer '{}'. Only 2D and 4D input layers are supported"
.format(len(net.inputs[blob_name].shape), blob_name))

out_blob = next(iter(net.outputs))"Loading IR to the plugin...")
plugin = IEPlugin(device=args.device, plugin_dirs=None)
exec_net = plugin.load(network=net)
n, c, h, w = net.inputs[input_blob].shape
if img_info_input_blob:
feed_dict[img_info_input_blob] = [h, w, 1]

if args.labels:
with open(args.labels, 'r') as f:
labels_map = [x.strip() for x in f]
labels_map = None

frame_h, frame_w = frame.shape[:2]
inf_start = time.time()
in_frame = cv2.resize(frame, (w, h))
in_frame = in_frame.transpose((2, 0, 1)) # Change data layout from HWC to CHW
in_frame = in_frame.reshape((n, c, h, w))
feed_dict[input_blob] = in_frame
res = exec_net.infer(feed_dict)[out_blob]

for obj in res[0][0]:
if obj[2] > -10:
xmin = int(obj[3] * frame_w)
ymin = int(obj[4] * frame_h)
xmax = int(obj[5] * frame_w)
ymax = int(obj[6] * frame_h)
color = ([0, 0, 255])
cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color, 2)

cv2.imshow("Detection Results", frame)

0 Kudos

Accepted Solutions
1 Reply