<s> """<STR_LIT>""" <EOL> import _init_paths <EOL> from fast_rcnn . config import cfg <EOL> from fast_rcnn . test import im_detect <EOL> from fast_rcnn . nms_wrapper import nms <EOL> from utils . timer import Timer <EOL> import matplotlib . pyplot as plt <EOL> import numpy as np <EOL> import scipy . io as sio <EOL> import caffe , os , sys , cv2 <EOL> import argparse <EOL> CLASSES = ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:train>' , '<STR_LIT>' ) <EOL> NETS = { '<STR_LIT>' : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } <EOL> def vis_detections ( im , class_name , dets , thresh = <NUM_LIT:0.5> ) : <EOL> """<STR_LIT>""" <EOL> inds = np . where ( dets [ : , - <NUM_LIT:1> ] >= thresh ) [ <NUM_LIT:0> ] <EOL> if len ( inds ) == <NUM_LIT:0> : <EOL> return <EOL> im = im [ : , : , ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ) ] <EOL> fig , ax = plt . subplots ( figsize = ( <NUM_LIT:12> , <NUM_LIT:12> ) ) <EOL> ax . imshow ( im , aspect = '<STR_LIT>' ) <EOL> for i in inds : <EOL> bbox = dets [ i , : <NUM_LIT:4> ] <EOL> score = dets [ i , - <NUM_LIT:1> ] <EOL> ax . add_patch ( <EOL> plt . Rectangle ( ( bbox [ <NUM_LIT:0> ] , bbox [ <NUM_LIT:1> ] ) , <EOL> bbox [ <NUM_LIT:2> ] - bbox [ <NUM_LIT:0> ] , <EOL> bbox [ <NUM_LIT:3> ] - bbox [ <NUM_LIT:1> ] , fill = False , <EOL> edgecolor = '<STR_LIT>' , linewidth = <NUM_LIT> ) <EOL> ) <EOL> ax . text ( bbox [ <NUM_LIT:0> ] , bbox [ <NUM_LIT:1> ] - <NUM_LIT:2> , <EOL> '<STR_LIT>' . format ( class_name , score ) , <EOL> bbox = dict ( facecolor = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) , <EOL> fontsize = <NUM_LIT> , color = '<STR_LIT>' ) <EOL> ax . set_title ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( class_name , class_name , <EOL> thresh ) , <EOL> fontsize = <NUM_LIT> ) <EOL> plt . axis ( '<STR_LIT>' ) <EOL> plt . tight_layout ( ) <EOL> plt . draw ( ) <EOL> def demo ( net , image_name ) : <EOL> """<STR_LIT>""" <EOL> im_file = os . path . join ( cfg . DATA_DIR , '<STR_LIT>' , image_name ) <EOL> im = cv2 . imread ( im_file ) <EOL> timer = Timer ( ) <EOL> timer . tic ( ) <EOL> scores , boxes = im_detect ( net , im ) <EOL> timer . toc ( ) <EOL> print ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( timer . total_time , boxes . shape [ <NUM_LIT:0> ] ) <EOL> CONF_THRESH = <NUM_LIT> <EOL> NMS_THRESH = <NUM_LIT> <EOL> for cls_ind , cls in enumerate ( CLASSES [ <NUM_LIT:1> : ] ) : <EOL> cls_ind += <NUM_LIT:1> <EOL> cls_boxes = boxes [ : , <NUM_LIT:4> * cls_ind : <NUM_LIT:4> * ( cls_ind + <NUM_LIT:1> ) ] <EOL> cls_scores = scores [ : , cls_ind ] <EOL> dets = np . hstack ( ( cls_boxes , <EOL> cls_scores [ : , np . newaxis ] ) ) . astype ( np . float32 ) <EOL> keep = nms ( dets , NMS_THRESH ) <EOL> dets = dets [ keep , : ] <EOL> vis_detections ( im , cls , dets , thresh = CONF_THRESH ) <EOL> def parse_args ( ) : <EOL> """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' , <EOL> default = <NUM_LIT:0> , type = int ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' , <EOL> choices = NETS . keys ( ) , default = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> return args <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> cfg . TEST . HAS_RPN = True <EOL> args = parse_args ( ) <EOL> prototxt = os . path . join ( cfg . MODELS_DIR , NETS [ args . demo_net ] [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> caffemodel = os . path . join ( cfg . DATA_DIR , '<STR_LIT>' , <EOL> NETS [ args . demo_net ] [ <NUM_LIT:1> ] ) <EOL> if not os . path . isfile ( caffemodel ) : <EOL> raise IOError ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( caffemodel ) ) <EOL> if args . cpu_mode : <EOL> caffe . set_mode_cpu ( ) <EOL> else : <EOL> caffe . set_mode_gpu ( ) <EOL> caffe . set_device ( args . gpu_id ) <EOL> cfg . GPU_ID = args . gpu_id <EOL> net = caffe . Net ( prototxt , caffemodel , caffe . TEST ) <EOL> print '<STR_LIT>' . format ( caffemodel ) <EOL> im = <NUM_LIT> * np . ones ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , dtype = np . uint8 ) <EOL> for i in xrange ( <NUM_LIT:2> ) : <EOL> _ , _ = im_detect ( net , im ) <EOL> im_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> for im_name in im_names : <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' . format ( im_name ) <EOL> demo ( net , im_name ) <EOL> plt . show ( ) </s>
