def main(): # Make output dir if not exists if not os.path.isdir(args.output_dir): os.makedirs(args.output_dir) # Make image output dirs if args.save_output_images > 0: output_image_dir = args.output_dir + 'image_outputs/' if not os.path.isdir(output_image_dir): os.makedirs(output_image_dir) # Create cityscapes manager class CS = cityscapes(args.cityscapes_dir) n_cl = len(CS.classes) # Get labeled frames for evaluation label_frames = CS.list_label_frames(args.split) # GPU runs out of memory, so keep using CPU # caffe.set_device(args.gpu_id) # caffe.set_mode_gpu() # Load FCN-8s network net = caffe.Net(args.caffemodel_dir + '/deploy.prototxt', args.caffemodel_dir + 'fcn-8s-cityscapes.caffemodel', caffe.TEST) hist_perframe = np.zeros((n_cl, n_cl)) # For all labeled frames for i, idx in enumerate(label_frames): if i % 10 == 0: print('Evaluating: %d/%d' % (i, len(label_frames))) city = idx.split('_')[0] # idx is city_shot_frame label = CS.load_label(args.split, city, idx) im_file = args.result_dir + '/' + idx + '_leftImg8bit.png' im = np.array( Image.open(im_file).resize((label.shape[1], label.shape[2]))) out = segrun(net, CS.preprocess(im)) hist_perframe += fast_hist(label.flatten(), out.flatten(), n_cl) if args.save_output_images > 0: label_im = CS.palette(label) pred_im = CS.palette(out) scipy.misc.imsave(output_image_dir + '/' + str(i) + '_pred.jpg', pred_im) scipy.misc.imsave(output_image_dir + '/' + str(i) + '_gt.jpg', label_im) scipy.misc.imsave(output_image_dir + '/' + str(i) + '_input.jpg', im) mean_pixel_acc, mean_class_acc, mean_class_iou, per_class_acc, per_class_iou = get_scores( hist_perframe) with open(args.output_dir + '/evaluation_results.txt', 'w') as f: f.write('Mean pixel accuracy: %f\n' % mean_pixel_acc) f.write('Mean class accuracy: %f\n' % mean_class_acc) f.write('Mean class IoU: %f\n' % mean_class_iou) f.write('************ Per class numbers below ************\n') for i, cl in enumerate(CS.classes): while len(cl) < 15: cl = cl + ' ' f.write('%s: acc = %f, iou = %f\n' % (cl, per_class_acc[i], per_class_iou[i]))
def get_chi_training_data(chi_df): for i in list(dfs.geo_avgs.T): if (i == 'Chicago Loop') or (i == 'Loop'): pass else: i_places = dfs.places['GeoArea'] == i workers = list( dfs.places[i_places]['MappedUser'].value_counts()) * 4 if len(workers) > 0: workers = math.ceil(sum(workers) / max(workers)) else: workers = 0 if i == 'Mckinley Park': i = 'McKinley Park' n = i + ' Chicago' area = calculate_area(gmclient, n) num_places = len(dfs.places[i_places]) walkscore, transitscore, bikescore = get_scores( n, 'Neighbourhood', 'IL') chi_df.loc[len(chi_df)] = \ (i, workers, area, num_places, \ walkscore, transitscore, bikescore)
async def scores(self, ctx): s = util.get_scores(self.conn, ctx.message.guild.id) if not s: return await ctx.send("No streaks in the server bro 😩") u = await asyncio.gather(*[self.bot.fetch_user(x[0]) for x in s]) u = filter(lambda x: type(x) is discord.User, u) s = [(x, *y[1:]) for x, y in zip(u, s)] msg = tabulate(s, headers=["User", "Current", "Highest", "Total"]) msg = f"```css\n{msg}```" await ctx.send(msg)
def main(): if not os.path.isdir(args.output_dir): os.makedirs(args.output_dir) if args.save_output_images > 0: output_image_dir = args.output_dir + 'image_outputs/' if not os.path.isdir(output_image_dir): os.makedirs(output_image_dir) CS = cityscapes(args.cityscapes_dir) n_cl = len(CS.classes) label_frames = CS.list_label_frames(args.split) print(label_frames) caffe.set_mode_cpu() net = caffe.Net(args.caffemodel_dir + '/deploy.prototxt', args.caffemodel_dir + 'fcn-8s-cityscapes.caffemodel', caffe.TEST) hist_perframe = np.zeros((n_cl, n_cl)) for i, idx in enumerate(label_frames): if i % 10 == 0: print('Evaluating: %d/%d' % (i, len(label_frames))) city = idx.split('_')[0] # idx is city_shot_frame label = CS.load_label(args.split, city, idx) im_file = args.result_dir + '/' + idx + '_leftImg8bit.png' ##print(im_file) im = np.array(Image.open(im_file)) #im = scipy.misc.imresize(im, (label.shape[1], label.shape[2])) im = np.array(Image.fromarray(im).resize((label.shape[2], label.shape[1]))) out = segrun(net, CS.preprocess(im)) hist_perframe += fast_hist(label.flatten(), out.flatten(), n_cl) if args.save_output_images > 0: label_im = CS.palette(label) pred_im = CS.palette(out) #scipy.misc.imsave(output_image_dir + '/' + str(i) + '_pred.jpg', pred_im) #scipy.misc.imsave(output_image_dir + '/' + str(i) + '_gt.jpg', label_im) #scipy.misc.imsave(output_image_dir + '/' + str(i) + '_input.jpg', im) imageio.imwrite(output_image_dir + '/' + str(i) + '_pred.jpg', pred_im) imageio.imwrite(output_image_dir + '/' + str(i) + '_gt.jpg', label_im) imageio.imwrite(output_image_dir + '/' + str(i) + '_input.jpg', im) #if i > 3: # break mean_pixel_acc, mean_class_acc, mean_class_iou, per_class_acc, per_class_iou = get_scores(hist_perframe) with open(args.output_dir + '/evaluation_results.txt', 'w') as f: f.write('Mean pixel accuracy: %f\n' % mean_pixel_acc) f.write('Mean class accuracy: %f\n' % mean_class_acc) f.write('Mean class IoU: %f\n' % mean_class_iou) f.write('************ Per class numbers below ************\n') for i, cl in enumerate(CS.classes): while len(cl) < 15: cl = cl + ' ' f.write('%s: acc = %f, iou = %f\n' % (cl, per_class_acc[i], per_class_iou[i]))
def main(): if not os.path.isdir(args.output_dir): os.makedirs(args.output_dir) if args.save_output_images > 0: output_image_dir = args.output_dir + 'image_outputs/' if not os.path.isdir(output_image_dir): os.makedirs(output_image_dir) CS = cityscapes(args.cityscapes_dir) n_cl = len(CS.classes) label_frames = CS.list_label_frames(args.split) # caffe.set_device(args.gpu_id) # caffe.set_mode_gpu() # net = caffe.Net(args.caffemodel_dir + '/deploy.prototxt', # args.caffemodel_dir + 'fcn-8s-cityscapes.caffemodel', # caffe.TEST) hist_perframe = np.zeros((n_cl, n_cl)) for i, idx in enumerate(label_frames): if i % 10 == 0: print('Evaluating: %d/%d' % (i, len(label_frames))) city = idx.split('_')[0] # idx is city_shot_frame label = CS.load_label(args.split, city, idx) im_file = args.result_dir + '/' + idx + '_leftImg8bit.png' # im = np.array(Image.open(im_file)) # out_path = args.cityscapes_dir + 'gtFine/val/' + city + '/' + idx + '_gtFine_color.png' # im = scipy.misc.imresize(im, (256, 256)) # im = scipy.misc.imresize(im, (label.shape[1], label.shape[2])) # out = segrun(net, CS.preprocess(im)) # out = scipy.misc.imresize(out, (label.shape[1], label.shape[2])) out = ReturnGrayImage(im_file) hist_perframe += fast_hist(label.flatten(), out.flatten(), n_cl) mean_pixel_acc, mean_class_acc, mean_class_iou, per_class_acc, per_class_iou = get_scores(hist_perframe) with open(args.output_dir + '/evaluation_results.txt', 'w') as f: f.write('Mean pixel accuracy: %f\n' % mean_pixel_acc) f.write('Mean class accuracy: %f\n' % mean_class_acc) f.write('Mean class IoU: %f\n' % mean_class_iou) f.write('************ Per class numbers below ************\n') for i, cl in enumerate(CS.classes): while len(cl) < 15: cl = cl + ' ' f.write('%s: acc = %f, iou = %f\n' % (cl, per_class_acc[i], per_class_iou[i]))
import imreg import chist parser = argparse.ArgumentParser() parser.add_argument('-c', default=10, type=int, dest='nclusters') parser.add_argument('-plot', action='store_true') args = parser.parse_args() nclusters = args.nclusters fout = 'score_' + str(nclusters) + '.pickle' if os.path.isfile(fout): with open(fout, 'r') as fin: (nm, cd) = pickle.load(fin) else: (nm, cd) = util.get_scores(nclusters, 'both', hbins=64, rand=True) with open(fout, 'w') as fout: pickle.dump((nm, cd), fout) (images, files) = util.get_images(nclusters) #print [(files[i], files[j]) for i in range(1000) for j in range(1000) # if (nm[i, j] > 15 and not util.same_cluster(i, j))] x = [] y = [] for i in range(nm.shape[0]): for j in range(nm.shape[1]): if nm[i, j] != 0: x.append((nm[i, j], cd[i, j])) if util.same_cluster(i, j): y.append(1)
import numpy as np import matplotlib.pylab as plt import scipy.linalg import sklearn.metrics import util CLUSTERS = 200 XINTERC = 0.001 bmat = np.ones((util.FILES_PER_CLUSTER, util.FILES_PER_CLUSTER), dtype = 'bool') blocks = [bmat for i in range(CLUSTERS)] true = scipy.linalg.block_diag(*blocks) hbins_array = [16, 25, 32, 50, 64, 80, 100, 128] aucs = [] for hbins in hbins_array: scores = -util.get_scores(CLUSTERS, 'hist', hbins=hbins) fpr, tpr, thresh = sklearn.metrics.roc_curve(true.flatten(), scores.flatten()) print np.interp(XINTERC, fpr, tpr) # plt.plot(fpr, tpr) # plt.show() # aucs.append(sklearn.metrics.roc_auc_score(true.flatten(), scores.flatten())) aucs.append(np.interp(XINTERC, fpr, tpr)) print (hbins, aucs[-1]) plt.plot(hbins_array, aucs) plt.show()