def main(argv=None): _init_output_directories() # step 1: create the negatives and positives directory if FLAGS.do_full_prepare: print('Loading labels from %s' % FLAGS.label_file) lr = LabelRecord() label_records = lr.load(FLAGS.label_file) all_bounding_boxes = Box.get_all_bounding_boxes(label_records) counter = 0 # fill examples, originals, negatives, and positives directories print('Processing images...') for (_, v) in label_records.items(): Progress.show_progress(counter) image = CXRImage.get_image_data(v.filename, FLAGS.image_path) basefilename = os.path.splitext(v.filename)[0] if v.hasBoundingBox: for i in range(0, v.boundingBoxes.shape[0]): box = v.boundingBoxes[i, :] #CXRImage.extract_center_and_write(image,box,1024,1024,FLAGS.positives_dir) CXRImage.extract_anisotropic_scale_and_write( image, box, FLAGS.image_size, FLAGS.image_size, FLAGS.positives_dir) CXRImage.write_image(image, FLAGS.examples_dir, "%s.jpg" % basefilename) else: i = np.int32( np.random.randint(0, all_bounding_boxes.shape[0] - 1)) box = all_bounding_boxes[i, :] CXRImage.extract_anisotropic_scale_and_write( image, box, FLAGS.image_size, FLAGS.image_size, FLAGS.negatives_dir) #CXRImage.extract_center_and_write(image,box,1024,1024,FLAGS.negatives_dir) if (v.hasBoundingBox): img = (CXRImage.xlate_image(image) * 255).astype(np.uint8) CXRImage.write_image_with_bounding_boxes( img, FLAGS.originals_dir, "%s.jpg" % basefilename, v.boundingBoxes) counter = counter + 1 # step 2: create the pre-training features by combining negatives and positives into pre_train.tfrecord print('\nCreating pre-train file...') rec = Record(1024, 1024, 1 if FLAGS.grayscale else 3) total = rec.create_pre_train_file(FLAGS.positives_dir, FLAGS.negatives_dir, FLAGS.pre_train_file) print('\n%d files combined in %s' % (total, FLAGS.pre_train_file))