def show_data(list_dat, num=4): from pylab import plt for dat in np.random.choice(list_dat, num): print dat im=cv2.imread(dat['filepath'])[:,:,::-1] plt.figure(1) plt.imshow(im) for bbox in dat['bboxes']: plt.gca().add_patch(plt.Rectangle((bbox['x1'], bbox['y1']), bbox['x2'] - bbox['x1'], bbox['y2'] - bbox['y1'], fill=False, edgecolor='red', linewidth=1) ) for idx, bbox in enumerate(dat['bboxes']): ann = np.array(Image.open(bbox['ann_path'])) if len(ann.shape)==3: ann = ann[:,:,0] # Make sure ann is a two dimensional np array. plt.figure(11+idx) plt.imshow(ann) plt.show()
def show_data(list_dat, num=4): from pylab import plt for dat in np.random.choice(list_dat, num): print dat im = cv2.imread(dat['filepath'])[:, :, ::-1] plt.figure(1) plt.imshow(im) for bbox in dat['bboxes']: plt.gca().add_patch( plt.Rectangle((bbox['x1'], bbox['y1']), bbox['x2'] - bbox['x1'], bbox['y2'] - bbox['y1'], fill=False, edgecolor='red', linewidth=1)) for idx, bbox in enumerate(dat['bboxes']): ann = cv2.imread(bbox['ann_path'], cv2.IMREAD_GRAYSCALE) plt.figure(11 + idx) plt.imshow(ann) plt.show()
# .............................................................. # ............ Subject exploration ............................. # .............................................................. rn = [ ( rd.random() * 2 - 1, rd.random() * 2 - 1 ) for _ in range( 5000 )] rn = np.array( rn ) distance = np.sqrt( ( rn**2 ).sum( axis = 1 ) ) frac = ( distance <= 1.0 ).sum( ) / len( distance ) pi_mcs = frac * 4 #....... PLOT ............................. fig = plt.figure( figsize = ( 8, 8 ) ) ax = fig.add_subplot( 1, 1, 1 ) circ = plt.Circle( (0,0), radius = 1, edgecolor = 'g', lw = 2.0, facecolor = 'None' ) box = plt.Rectangle( (-1,-1), 2,2, edgecolor = 'b', alpha = 0.3 ) ax.add_patch( circ ) ax.add_patch( box ) plt.plot( rn[ :, 0], rn[:, 1 ], 'r.' ) plt.xlim( -1.1, 1.1) plt.ylim( -1.1, 1.1) # .............................................................. # ............ MonteCarlo function: NumPy....................... # .............................................................. def mcs_pi_np( n ): rn = [ ( rd.random() * 2 - 1, rd.random() * 2 - 1 ) for _ in range( n )] rn = np.array( rn ) distance = np.sqrt( ( rn**2 ).sum( axis = 1 ) ) frac = ( distance <= 1.0 ).sum( ) / n
ttxt = 'case {} and test function {}: benchmarking {}'.format( nc, nc, eat) ttxt += '\nbest error: mean {} and std {} after {} evaluations'.format( mean(y[:, -1]), std(y[:, -1]), mean(neval[:, -1])) date = give_datestring() plt.figure() for i, xval in enumerate(x[0]): if i == 0: rxmin, rxmax = xval - 0.004, xval + 0.004 else: rxmin, rxmax = xval - 0.03, xval + 0.03 rymin, rymax = np.min(y[:, i]), np.max(y[:, i]) rect = plt.Rectangle((rxmin, rymin), rxmax - rxmin, rymax - rymin, facecolor='grey', alpha=0.4) plt.gca().add_patch(rect) for i, sc in enumerate(loaded): plt.plot(x[i], y[i]) if nc != 8: plt.semilogy() #if nc in yldict: plt.ylim(yldict[nc]) plt.xlabel('FES / maxFES') plt.ylabel(r'error = $f_i(x)-f_i(x^*)$') plt.suptitle(ttxt, x=0.5, y=0.98, ha='center', va='top', fontsize=10) plt.suptitle(date, x=0.97, y=0.02, ha='right', va='bottom', fontsize=8) plt.savefig( join( plotloc, 'allruns_c' + str(nc).zfill(3) + '_' + eat + '_' + df[:-1] + '.png'))