def GeneratePlot(outfile, Filename, xpixel, ypixel, nyanFlag=0, nyanAudio=0): video = imageio.get_reader(Filename, 'ffmpeg') colorArr = [] maxLen = int(len(video)) gradient = np.linspace(0,1,256) gradient = np.vstack((gradient, gradient)) index = range(maxLen) RGB = [[],[],[]] #0 - Red, 1 - Green, 2 - Blue progress = "" if(nyanAudio): progress = NyanBar(audiofile="./NyanCat.mp3") elif(nyanFlag): progress = NyanBar() try: print "Starting Collection" for i in index: try: frame = video.get_data(i) pass except KeyboardInterrupt: print "\nEnding Collection" break tempArr = frame[ypixel,xpixel] #Get the Frame at X=xpixel and Y=ypixel for j in range(3): RGB[j].append(float(tempArr[j])/256.0) #Normalizing the RGB values to 256 to get RGB value less than 1 for Matplotlib cmap colorArr.append([x[i] for x in RGB]) #Get the RGB values of the most recent entry and appent to colorArr if(nyanFlag): progress.update(int(float(i)/float(maxLen) * 100)) #sys.stdout.write("\rFrame %i of %i" % (i, maxLen)) #sys.stdout.flush() if(nyanFlag): progress.finish() #RGB Plots for Rates plt.plot(RGB[0], 'r') plt.plot(RGB[1], 'g') plt.plot(RGB[2], 'b') plt.savefig(AppendTitleToFilename(outfile, "RGB")) plt.clf() #Making Colorbar cmap1 = LinearSegmentedColormap.from_list("cmap", colorArr, N=256, gamma=1.0) #Need normalized RGB to 256 therefore from 0 to 1 gradient = np.linspace(0,1,256) gradient = np.vstack((gradient, gradient)) plt.imshow(gradient, aspect='auto', cmap=cmap1) plt.savefig(outfile) plt.clf() return except KeyboardInterrupt: print "\nEnding Plot"
def __init__(self, img_paths, outfile_name=("data/align/fundus_photo_aligner_%s.csv" % str(uuid.uuid4())[:8])): path = '/'.join(img_paths[0].split('/')[:-1]) img_names = [img_path.split('/')[-1] for img_path in img_paths] ext = img_names[0].split('.')[-1] ids = set([img_path.split('_')[0] for img_path in img_names]) assert((len(ids) * 2) == len(img_names)) grouped_img_names = [["%s_left" % id, "%s_right" % id] for id in ids] self.labels = {} print ''.join([" %i%%|" % (j*10) for j in xrange(1,10)] + [' 100%|']) pb = NyanBar(tasks=len(grouped_img_names)) with open(outfile_name, 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow(['image','horizontal_flip','vertical_flip']) for img_names in grouped_img_names: img_paths = ["%s/%s.%s" % (path, name, ext) for name in img_names] fundus_photos = [FundusPhoto(img_path) for img_path in img_paths] for i, fundus_photo in enumerate(fundus_photos): fundus_photo.refine_center() direct = fundus_photo.has_notch() lens_flip_vector = np.array([0,0] if direct else [1,1]) left_right_flip_vector = np.array([0,1] if i == 0 else [0,0]) final_flip_vector = (lens_flip_vector + left_right_flip_vector) % 2 writerow = [img_names[i]] + final_flip_vector.tolist() writer.writerow(writerow) self.labels[img_names[i]] = direct pb.task_done() pb.finish() print("Done! created: %s" % outfile_name)
def benchmark_put_with_many_filters(): hosts = ["bloom1", "bloom2", "bloom3", "bloom4"] client = BloomRouter(hosts, "g{}".format(random.randint(1, 100000), filter_count=16)) progress = NyanBar(tasks=testsize) for i in range(testsize): progress.task_done() keys = [str(uuid.uuid4()) for _ in range(num_keys)] client.add(keys) progress.finish()
def put_then_get_with_one_filter(): hosts = ["bloom1", "bloom2", "bloom3", "bloom4"] client = BloomRouter(hosts, "f{}".format(random.randint(1, 100000)), filter_count=1) progress = NyanBar(tasks=testsize) for i in range(testsize): progress.task_done() keys = [str(uuid.uuid4()) for _ in range(num_keys)] client.add(keys) assert client.get(keys) progress.finish()
def package_data(directory, datasets, image_shape, outfile_path): """ Outputs a *.npz file of image data in 3 sets :type directory: string :param directory: directory of image data :type datasets: tuple of dictionaries, string -> Any :param datasets: dictionaries should be in the order training, validation, test. The key is the image filename and the value is the true label :type image_shape: tuple of ints :type outfile_path: string """ assert(len(datasets) == 3) xsize = numpy.prod(image_shape) x_datasets = [numpy.zeros((len(dataset), xsize), dtype=numpy.uint8) for dataset in datasets] y_datasets = [numpy.array(dataset.values(), dtype=numpy.uint8) for dataset in datasets] print "| " + ("⚐ ⚑ " * 19) + "-|" pb = NyanBar(tasks=sum([len(dataset) for dataset in datasets])) for j, dataset in enumerate(datasets): for i, image_name in enumerate(dataset.keys()): pb.task_done() im = Image.open(directory + image_name) x_datasets[j][i, :] = numpy.array(im.getdata(), dtype=numpy.uint8).reshape(xsize) pb.finish() print '... saving data' # cPickle too slow (takes many minutes for tens of thousands of images over 100x100x3) saveme = [x_datasets[0], y_datasets[0], x_datasets[1], y_datasets[1], x_datasets[2], y_datasets[2]] numpy.savez(open(outfile_path, 'wb'), *saveme) print 'done'
if len(sys.argv) == 2: # single image predict_single_image(sys.argv[1]) elif len(sys.argv) == 4: # batch of single images label_csv = sys.argv[1] inpath = sys.argv[2] outpath = sys.argv[3] true_labels = [] predicted_labels = [] with open(label_csv, 'rU') as csvfile: reader = csv.reader(csvfile, dialect=csv.excel_tab, delimiter=',') next(reader, None) # skip header print ''.join([" %i%%|" % (j*10) for j in xrange(1,10)] + [' 100%|']) pb = NyanBar(tasks=(sum(1 for row in open(label_csv, 'rU'))-1)) for row in reader: imgname = row[0] true_label = 1 if (row[1] == 'tr' or row[1] == 'br' or row[1] == '1') else 0 title_prefix = "True Label: %s" % true_label predicted_label = predict_single_image(inpath + imgname, title_prefix=title_prefix, save_path=(outpath + imgname), true_label=true_label) true_labels.append(true_label) predicted_labels.append(predicted_label) pb.task_done() pb.finish() accuracy, precision = binary_accuracy_precision(true_labels, predicted_labels) print("Accuracy: %.3f. Precision: %.3f." % (accuracy, precision)) elif len(sys.argv) == 3: # batch of doubled images true_label_csv = sys.argv[1]
default=False, action='store_true', help='show a Nyan Cat progress bar') return arg_parser.parse_args() def lint_file(linter, file): linter.set_file(file) if args.fix: linter.format() else: linter.lint() @atexit.register def clean_up(): if nyan_progress: nyan_progress.finish() args = parse_args() nyan_progress = None if args.nyan: nyan_mp3_file = os.path.dirname(__file__) + '/nyan.mp3' nyan_progress = NyanBar(audiofile=nyan_mp3_file) lintthesql(args)
evaluation_results = [] for ei, e in enumerate(emails_dir): evaluation = "" emails = [] for d in os.listdir(e): if ("spam" in d or "ham" in d) and os.path.isfile(os.path.join(e, d)): emails.append(os.path.join(e, d)) else: print "The test filename must either contain word *spam* or *ham* indicating its class!" print "The filter won't be tested on `%s` file." % os.path.join( e, d) if show_progress and progress_bar == "nyan": print "Test [%d/%d]" % (ei + 1, len(emails_dir)) progress = NyanBar(tasks=100) tp, tn, fp, fn = 0, 0, 0, 0 evaluation_start_time = time.time() for ii, i in enumerate(emails): if show_progress and progress_bar == "classic": print "[%d/%d] %.2d%% (%s)" % (ei + 1, len(emails_dir), 100. * ii / len(emails), i) elif show_progress and progress_bar == "nyan": progress.update(100. * ii / len(emails)) current_email = execute % os.path.abspath(i) if "spam" in os.path.split(i)[1]: ground_truth = "spam" elif "ham" in os.path.split(i)[1]: ground_truth = "ham" else: sys.exit(
from nyanbar import NyanBar import time progress = NyanBar(audiofile="NyanCat-original.mp3") for n in range(100): time.sleep(.3) progress.update(n) progress.finish()
# Number of hours to run the experiment nHours = 18 # Sampling every x minutes intervals = 5 nMins = nHours * 60 timer = 0 leds = 1 # Initialize the leds with the first one only pfd.leds[0].turn_on() pfd.leds[0].set_high() progress = NyanBar() while timer <= nMins: # Update progress bar progress.update((timer / nMins) * 100) # Light up the transilluminator pfd.relays[0].value = 1 # Set camera values camera.awb_gains = 1, 0.5 camera.brightness = 55 camera.saturation = 30 camera.exposure_compensation = 25 camera.contrast = 50 camera.shutter_speed = 220000