def main(): try: instanceSize = 10 step = 1 numOfClasses = 100 filename = 'detector_7_no_5_angle_2.jpg' mode = 'PRO' image_files, bubble_num, bubble_regions = getinfo() data_set = ds.read_data_sets( instanceSize = instanceSize, stride = step, instanceMode = 'test', labelMode = mode, imageName = filename, dtype = tf.float32, plot_show = 0, label_mutiplier = 1.0) print data_set.labels.shape[-1] print 'Sum of labels: ' + str(np.sum(data_set.labels)) print 'Number bubbles: ' + str(bubble_num[image_files.index(filename)]) except KeyboardInterrupt: print "Shutdown requested... exiting" except Exception: traceback.print_exc(file=sys.stdout) sys.exit(0)
def main(): try: instanceSize = 20 step = 20 numOfClasses = 100 print 'Testing data generation ... ' data_set = ds.read_data_sets(instanceSize, step, numOfClasses, 'train', 'PRO', plot_show = 0) print 'Instances shape :' print data_set.images.shape print 'label shape :' print data_set.labels.shape print 'Testing batch data generation :' batch_size = 1000 batch_num = 1000 for i in range(batch_num): print ('batch num: ' + str(i) + str(data_set.next_batch(batch_size)[0].shape) + str(data_set.next_batch(batch_size)[1].shape)) ds.read_data_sets(instanceSize, step, numOfClasses, 'test', 'PRO', 'detector_1_no_5_angle_3.jpg', plot_show = 1) ds.read_data_sets(instanceSize, step, numOfClasses, 'train', 'NUM', plot_show = 1) ds.read_data_sets(instanceSize, step, numOfClasses, 'test', 'NUM', 'detector_1_no_5_angle_3.jpg', plot_show = 1) except KeyboardInterrupt: print "Shutdown requested... exiting" except Exception: traceback.print_exc(file=sys.stdout) sys.exit(0)
def labellinearity(patch_size, stride, labelMode = 'PRO', label_mutiplier = 1, progress_show = 1, plot_show = 1): gv.ds_show_filename = False image_files, bubble_num, bubble_regions = getinfo() bubble_num_afterlabel = np.zeros(len(image_files)) probar = progress.progress(0, len(image_files)) for i, image in enumerate(image_files): probar.setCurrentIteration(i+1) probar.setInfo(prefix_info = 'dataset linearity ...', suffix_info = image) probar.printProgress() image_ds = ds.read_data_sets( instanceSize = patch_size, stride = stride, instanceMode = 'test', labelMode = labelMode, imageName = image, label_mutiplier = label_mutiplier) labels = image_ds.labels bubble_num_afterlabel[i] = np.sum(labels) slope, intercept, r_value, p_value, std_err = (linregress(bubble_num, bubble_num_afterlabel)) if(plot_show == 1): yfit = slope * bubble_num + intercept fig, ax = plt.subplots(1,1) ax.set_title('Linearity of Labeling Methods') ax.set_xlabel('Bubble number counted manually') ax.set_ylabel('Bubble number after labeling') ax.scatter(bubble_num, bubble_num_afterlabel, color = 'blue', label = 'bubble number') ax.plot(bubble_num, yfit, color = 'red', label = 'linear regression') handles, labels = ax.get_legend_handles_labels() ax.legend(handles, labels, loc="upper left") text_x = np.amax(bubble_num)*0.6 text_y = np.amax(bubble_num_afterlabel)*0.1 text = "r_squared: %.5f\nstd_err: %.5f" % (r_value**2, std_err) ax.annotate(text, xy = (text_x, text_y), xytext = (text_x, text_y)) plt.show() return ([[slope, intercept, r_value, p_value, std_err], bubble_num, bubble_num_afterlabel])