@@ -158,11 +158,24 @@ def plot_image_with_boxes(img, boxes, pred_cls):
158158
159159 for i in range (len (boxes )):
160160 # Draw Rectangle with the coordinates
161- cv2 .rectangle (img , boxes [i ][0 ], boxes [i ][1 ], color = (0 , 255 , 0 ), thickness = rect_th )
162161
162+ cv2 .rectangle (
163+ img ,
164+ (int (boxes [i ][0 ][0 ]), int (boxes [i ][0 ][1 ])),
165+ (int (boxes [i ][1 ][0 ]), int (boxes [i ][1 ][1 ])),
166+ color = (0 , 255 , 0 ),
167+ thickness = rect_th ,
168+ )
163169 # Write the prediction class
164- cv2 .putText (img , pred_cls [i ], boxes [i ][0 ], cv2 .FONT_HERSHEY_SIMPLEX , text_size , (0 , 255 , 0 ), thickness = text_th )
165-
170+ cv2 .putText (
171+ img ,
172+ pred_cls [i ],
173+ (int (boxes [i ][0 ][0 ]), int (boxes [i ][0 ][1 ])),
174+ cv2 .FONT_HERSHEY_SIMPLEX ,
175+ text_size ,
176+ (0 , 255 , 0 ),
177+ thickness = text_th ,
178+ )
166179 plt .axis ("off" )
167180 plt .imshow (img .astype (np .uint8 ), interpolation = "nearest" )
168181 plt .show ()
@@ -215,7 +228,7 @@ def append_loss_history(loss_history, output):
215228 "batch_size" : 1 ,
216229 "image_file" : "banner-diverse-group-of-people-2.jpg" ,
217230 "resume" : False ,
218- "path" : "xp/ " ,
231+ "path" : "" ,
219232 }
220233
221234 pp = pprint .PrettyPrinter (indent = 4 )
@@ -280,3 +293,14 @@ def append_loss_history(loss_history, output):
280293 file .write (json .dumps (loss_history ))
281294
282295 np .save (os .path .join (config ["path" ], "patch" ), attack ._patch )
296+
297+ predictions_adv = frcnn .predict (x = x_patch )
298+
299+ for i in range (image .shape [0 ]):
300+ print ("\n Predictions adversarial image {}:" .format (i ))
301+
302+ # Process predictions
303+ predictions_adv_class , predictions_adv_boxes , predictions_adv_class = extract_predictions (predictions_adv [i ])
304+
305+ # Plot predictions
306+ plot_image_with_boxes (img = x_patch [i ].copy (), boxes = predictions_adv_boxes , pred_cls = predictions_adv_class )
0 commit comments