def test_get_filename_from_imageinfo(self): parser = FilenameParser(EMBRYO_FOLDER) for info in INFOS: partial = parser.get_partial_filename_from_imageinfo(info) filename = parser.get_filename_from_imageinfo(info) truth = os.path.join(EMBRYO_FOLDER, partial) self.assertEqual(filename, truth)
def _predict(self, filenames): images = read_images_for_torch(filenames).to(self.device) labels = self.network.predict(images).astype('uint8') infos = [ FilenameParser.get_imageinfo_from_filename(nm) for nm in filenames ] return self.pack_into_annotated_images(infos, labels)
def _predict(self, filenames_and_boxes): input_x = self._read_images_for_stage(filenames_and_boxes) stage_probs = self.network.predict_proba(input_x) infos = [ FilenameParser.get_imageinfo_from_filename(nm) for nm, box in filenames_and_boxes] return self.pack_into_annotated_images(infos, stage_probs)
def test_get_partial_filename_from_imageinfo(self): partial_name = FilenameParser.get_partial_filename_from_imageinfo( INFO_F0) correct = os.path.join( INFO_F0.slide, 'WELL' + str(INFO_F0.well).rjust(2, '0'), 'F{}'.format(INFO_F0.focus), str(INFO_F0.image_number).rjust(3, '0') + '.jpg') self.assertEqual(correct, partial_name)
def _grab_names_and_boxes_for_stages( self, stage_smooth, valid_stages, names_and_boxes): infos = [ FP.get_imageinfo_from_filename(nm) for nm, _ in names_and_boxes] out = [ name_and_box for name_and_box, info in zip(names_and_boxes, infos) if stage_smooth[info].annotation in valid_stages] return out
def test_grab_1cell_names_and_boxes(self): stages = make_fake_smoothed_stages() box = (1, 1, 100, 100) names_and_boxes = [ (FP.get_partial_filename_from_imageinfo(i.info), box) for i in stages.iterate_over_images()] p = Pipeline('cpu') onecell_names_boxes = p._grab_1cell_names_and_boxes( stages, names_and_boxes) images_in_onecell_stage = [ i for i in stages.iterate_over_images() if i.annotation == 1] for name, _ in onecell_names_boxes: info = FP.get_imageinfo_from_filename(name) self.assertEqual(stages[info].annotation, 1) self.assertEqual( len(images_in_onecell_stage), len(onecell_names_boxes))
def test_create_from_filename_and_data(self): filename = ( '/media/brian/Data/Dalit-Embryo-Images/training-data-folders/' + 'D2016_06_03_S1113_I313_pdb/WELL06/F0/168.jpg') data = [1, 2, 4] image = AnnotatedImage.create_from_filename_and_data( filename, data) true_info = FilenameParser.get_imageinfo_from_filename(filename) self.assertEqual(image.info, true_info) self.assertEqual(image.annotation, data)
def test_grab_cleavage_names_and_boxes(self): stages = make_fake_smoothed_stages() box = (1, 1, 100, 100) names_and_boxes = [ (FP.get_partial_filename_from_imageinfo(i.info), box) for i in stages.iterate_over_images()] p = Pipeline('cpu') cleavage_names_boxes = p._grab_cleavage_names_and_boxes( stages, names_and_boxes) cleavage_stages = {1, 2, 3, 4, 5, 6, 7, 8} images_in_cleavage_stage = [ i for i in stages.iterate_over_images() if i.annotation in cleavage_stages] for name, _ in cleavage_names_boxes: info = FP.get_imageinfo_from_filename(name) self.assertIn(stages[info].annotation, cleavage_stages) self.assertEqual( len(images_in_cleavage_stage), len(cleavage_names_boxes))
def _predict(self, filenames_and_boxes): boxes = [box for filename, box in filenames_and_boxes] filenames = [filename for filename, box in filenames_and_boxes] outputs_raw = [ self._predict_single_timepoint_raw(*name_and_box) for name_and_box in filenames_and_boxes ] output = self._transform_to_final_output(outputs_raw, boxes) infos = [ FilenameParser.get_imageinfo_from_filename(nm) for nm in filenames ] return self.pack_into_annotated_images(infos, output)
def _predict(self, f0_filenames_and_boxes): filenames = [nm for nm, box in f0_filenames_and_boxes] boxes = [box for nm, box in f0_filenames_and_boxes] augmented_names = [augment_focus(nm) for nm in filenames] fm_filenames_and_boxes = [ (names[0], box) for names, box in zip(augmented_names, boxes)] fp_filenames_and_boxes = [ (names[2], box) for names, box in zip(augmented_names, boxes)] frag_f0 = self._predict_for_focus_level(f0_filenames_and_boxes) frag_fm = self._predict_for_focus_level(fm_filenames_and_boxes) frag_fp = self._predict_for_focus_level(fp_filenames_and_boxes) frag_values = np.mean([frag_f0, frag_fm, frag_fp], axis=0) infos = [ FilenameParser.get_imageinfo_from_filename(nm) for nm in filenames] return self.pack_into_annotated_images(infos, frag_values)
def test_get_imageinfo_from_filename(self): true_info = INFO_F0 parser = FilenameParser(EMBRYO_FOLDER) filename = parser.get_filename_from_imageinfo(true_info) parsed_info = parser.get_imageinfo_from_filename(filename) self.assertEqual(parsed_info, true_info)