def test_as_random_patches(self): if self.data_dir is None: unittest.TestCase.skipTest(self, "DLPY_DATA_DIR is not set in the environment variables") my_images = ImageTable.load_files(self.s, path=self.data_dir+'giraffe_dolphin_small') out = my_images.as_random_patches(x=0, y=0, width=200, height=200, step_size=200, output_width=100, output_height=100, inplace=False) out = out.image_summary column_list = ['jpg', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight', 'meanWidth', 'meanHeight', 'mean1stChannel', 'min1stChannel', 'max1stChannel', 'mean2ndChannel', 'min2ndChannel', 'max2ndChannel', 'mean3rdChannel', 'min3rdChannel', 'max3rdChannel'] self.assertTrue(int(out[1]) == 100) self.assertTrue(int(out[2]) == 100) self.assertTrue(int(out[3]) == 100) self.assertTrue(int(out[4]) == 100) self.assertTrue(int(out[5]) == 100) self.assertTrue(int(out[6]) == 100) my_images = ImageTable.load_files(self.s, path=self.data_dir+'giraffe_dolphin_small') out = my_images.as_random_patches(x=0, y=0, width=None, height=None, step_size=None, output_width=None, output_height=None, inplace=False) out = out.image_summary column_list = ['jpg', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight', 'meanWidth', 'meanHeight', 'mean1stChannel', 'min1stChannel', 'max1stChannel', 'mean2ndChannel', 'min2ndChannel', 'max2ndChannel', 'mean3rdChannel', 'min3rdChannel', 'max3rdChannel'] self.assertTrue(int(out[1]) == 224) self.assertTrue(int(out[2]) == 224) self.assertTrue(int(out[3]) == 224) self.assertTrue(int(out[4]) == 224) self.assertTrue(int(out[5]) == 224) self.assertTrue(int(out[6]) == 224) my_images = ImageTable.load_files(self.s, path=self.data_dir+'giraffe_dolphin_small') out = my_images.as_random_patches(x=0, y=0, width=None, height=200, step_size=None, output_width=None, output_height=None, inplace=False) out = out.image_summary column_list = ['jpg', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight', 'meanWidth', 'meanHeight', 'mean1stChannel', 'min1stChannel', 'max1stChannel', 'mean2ndChannel', 'min2ndChannel', 'max2ndChannel', 'mean3rdChannel', 'min3rdChannel', 'max3rdChannel'] self.assertTrue(int(out[1]) == 200) self.assertTrue(int(out[2]) == 200) self.assertTrue(int(out[3]) == 200) self.assertTrue(int(out[4]) == 200) self.assertTrue(int(out[5]) == 200) self.assertTrue(int(out[6]) == 200)
def test_captioning_table_3(self): if self.data_dir is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR is not set in the environment variables") if self.data_dir_local is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR_LOCAL is not set in the environment variables") img_path = self.data_dir + 'imageCaptioning_images' image_table = ImageTable.load_files(self.s, path=img_path) image_table.resize(width=224) captions_file = self.data_dir_local + 'image_captions.txt' features_model = VGG16(self.s, width=224, height=224, pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5') detection_model = Model(self.s) detection_model.load(self.data_dir + 'YOLOV2_MULTISIZE.sashdat') detection_model.load_weights(self.data_dir + 'YoloV2_Multisize_weights.sashdat') word_embeddings = self.data_dir_local + 'word_embeddings.txt' self.assertTrue( create_captioning_table(self.s, image_table, features_model, captions_file, obj_detect_model=detection_model, word_embeddings_file=word_embeddings) is not None)
def test_load_images(self): if self.data_dir is None: unittest.TestCase.skipTest(self, "DLPY_DATA_DIR is not set in the environment variables") img_path = self.data_dir+'giraffe_dolphin_small' my_images = ImageTable.load_files(self.s, path=img_path) self.assertTrue(len(my_images) > 0)
def test_captioning_table_1(self): if self.data_dir is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR is not set in the environment variables") file_dependency = self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest( self, "File, {}, not found.".format(file_dependency)) if self.data_dir_local is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR_LOCAL is not set in the environment variables") img_path = self.data_dir + 'imageCaptioning_images' image_table = ImageTable.load_files(self.s, path=img_path) image_table.resize(width=224) captions_file = self.data_dir_local + 'image_captions.txt' features_model = VGG16(self.s, width=224, height=224, pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5') self.assertTrue( create_captioning_table(self.s, image_table, features_model, captions_file) is not None)
def test_object_table_2(self): if self.data_dir is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR is not set in the environment variables") file_dependency = self.data_dir + 'YOLOV2_MULTISIZE.sashdat' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest( self, "File, {}, not found.".format(file_dependency)) file_dependency = self.data_dir + 'YoloV2_Multisize_weights.sashdat' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest( self, "File, {}, not found.".format(file_dependency)) img_path = self.data_dir + 'imageCaptioning_images' image_table = ImageTable.load_files(self.s, path=img_path) image_table.resize(width=416) word_embeddings = self.data_dir + 'no_file.txt' detection_model = Model(self.s) detection_model.load(self.data_dir + 'YOLOV2_MULTISIZE.sashdat') detection_model.load_weights(self.data_dir + 'YoloV2_Multisize_weights.sashdat') self.assertRaises( DLPyError, lambda: create_embeddings_from_object_detection( self.s, image_table, detection_model, word_embeddings))
def test_filter_by_filename_5(self): if self.data_dir is None: unittest.TestCase.skipTest(self, "DLPY_DATA_DIR is not set in the environment variables") img_path = self.data_dir+'giraffe_dolphin_small' table = ImageTable.load_files(self.s, path=img_path) filename = [1,'text',5.3] self.assertRaises(ValueError, lambda:filter_by_filename(table, filename, filtered_name=None))
def test_filter_by_image_id_1(self): if self.data_dir is None: unittest.TestCase.skipTest(self, "DLPY_DATA_DIR is not set in the environment variables") img_path = self.data_dir+'giraffe_dolphin_small' table = ImageTable.load_files(self.s, path=img_path) image_id = '1' self.assertRaises(ValueError, lambda:filter_by_image_id(table, image_id, filtered_name=1))
def test_show(self): if self.data_dir is None: unittest.TestCase.skipTest(self, "DLPY_DATA_DIR is not set in the environment variables") img_path = self.data_dir+'giraffe_dolphin_small' my_images = ImageTable.load_files(self.s, path=img_path) # the test shold be clean, even if selected are less than nimages my_images.show(nimages=2, where='_id_ eq 57')
def test_filter_by_image_id_2(self): if self.data_dir is None: unittest.TestCase.skipTest(self, "DLPY_DATA_DIR is not set in the environment variables") img_path = self.data_dir+'giraffe_dolphin_small' table = ImageTable.load_files(self.s, path=img_path) image_id = ['1','3','4'] filtered = filter_by_image_id(table, image_id, filtered_name=None) self.assertTrue(filtered.numrows().numrows == 3)
def test_filter_by_filename_3(self): if self.data_dir is None: unittest.TestCase.skipTest(self, "DLPY_DATA_DIR is not set in the environment variables") img_path = self.data_dir+'giraffe_dolphin_small' table = ImageTable.load_files(self.s, path=img_path) filename = ['giraffe_', 'dolphin_'] filtered = filter_by_filename(table, filename, filtered_name=None) filtered = ImageTable.from_table(filtered) self.assertTrue(filtered.label_freq.loc['Giraffe'][1]>0) self.assertTrue(filtered.label_freq.loc['Dolphin'][1]>0)
def test_get_image_features_1(self): if self.data_dir is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR is not set in the environment variables") img_path = self.data_dir + 'imageCaptioning_images' image_table = ImageTable.load_files(self.s, path=img_path) image_table.resize(width=224) features_model = VGG16(self.s, width=224, height=224) dense_layer = 'fc10000' self.assertRaises( DLPyError, lambda: get_image_features(self.s, features_model, image_table, dense_layer))
def viyaStartUp(): s= CAS('xx.xxx.xxx.xxx',5570,'viyademo01','demopw') s.loadactionset('image') s.loadactionset('deepLearn') model_load = Model(s) model_file = '/root/fullModel/Yolov2.sashdat' model_load.load(path=model_file) #test = ImageTable.load_files(conn=s, caslib='dnfs', path='/data/Poa/testData/labelled_images') test = ImageTable.load_files(conn=s, caslib='dnfs', path='/data/Poa/validation') test.resize(height=416, width=416, inplace=True) prd = model_load.predict(data=test) return [s,prd]
def test_get_image_features_3(self): if self.data_dir is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR is not set in the environment variables") img_path = self.data_dir + 'imageCaptioning_images' image_table = ImageTable.load_files(self.s, path=img_path) image_table.resize(width=224) features_model = VGG16(self.s, width=224, height=224, pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5') dense_layer = 'fc7' self.assertTrue( get_image_features(self.s, features_model, image_table, dense_layer) is not None)
def test_captioning_table_2(self): if self.data_dir is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR is not set in the environment variables") file_dependency = self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest( self, "File, {}, not found.".format(file_dependency)) file_dependency = self.data_dir + 'YOLOV2_MULTISIZE.sashdat' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest( self, "File, {}, not found.".format(file_dependency)) file_dependency = self.data_dir + 'YoloV2_Multisize_weights.sashdat' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest( self, "File, {}, not found.".format(file_dependency)) if self.data_dir_local is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR_LOCAL is not set in the environment variables") img_path = self.data_dir + 'imageCaptioning_images' image_table = ImageTable.load_files(self.s, path=img_path) image_table.resize(width=224) captions_file = self.data_dir_local + 'image_captions.txt' features_model = VGG16(self.s, width=224, height=224, pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5') detection_model = Model(self.s) detection_model.load(self.data_dir + 'YOLOV2_MULTISIZE.sashdat') detection_model.load_weights(self.data_dir + 'YoloV2_Multisize_weights.sashdat') self.assertRaises( DLPyError, lambda: create_captioning_table(self.s, image_table, features_model, captions_file, obj_detect_model=detection_model))
def test_object_table_1(self): if self.data_dir is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR is not set in the environment variables") if self.data_dir_local is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR_LOCAL is not set in the environment variables") img_path = self.data_dir + 'imageCaptioning_images' image_table = ImageTable.load_files(self.s, path=img_path) image_table.resize(width=416) word_embeddings = self.data_dir_local + 'word_embeddings.txt' detection_model = Model(self.s) detection_model.load(self.data_dir + 'YOLOV2_MULTISIZE.sashdat') detection_model.load_weights(self.data_dir + 'YoloV2_Multisize_weights.sashdat') tbl = create_embeddings_from_object_detection(self.s, image_table, detection_model, word_embeddings) self.assertTrue(tbl is not None)
def test_heat_map_analysis(self): if self.data_dir is None: unittest.TestCase.skipTest(self, 'DLPY_DATA_DIR is not set in the environment variables') if not file_exist_on_server(self.s, self.data_dir + 'ResNet-50-model.caffemodel.h5'): unittest.TestCase.skipTest(self, "File, {}, not found.".format(self.data_dir + 'ResNet-50-model.caffemodel.h5')) from dlpy.applications import ResNet50_Caffe from dlpy.images import ImageTable pre_train_weight_file = os.path.join(self.data_dir, 'ResNet-50-model.caffemodel.h5') my_im = ImageTable.load_files(self.s, self.data_dir+'giraffe_dolphin_small') my_im_r = my_im.resize(width=224, inplace=False) model = ResNet50_Caffe(self.s, model_table='ResNet50_Caffe', n_classes=2, n_channels=3, width=224, height=224, scale=1, random_flip='none', random_crop='none', offsets=my_im_r.channel_means, pre_trained_weights=True, pre_trained_weights_file=pre_train_weight_file, include_top=False) model.fit(data=my_im_r, mini_batch_size=1, max_epochs=1) model.heat_map_analysis(data=my_im_r, mask_width=None, mask_height=None, step_size=None, max_display=1) self.assertRaises(ValueError, lambda:model.heat_map_analysis(mask_width=56, mask_height=56, step_size=8, display=False)) self.assertRaises(ValueError, lambda:model.heat_map_analysis(data=my_im, mask_width=56, mask_height=56, step_size=8, display=False)) try: from numpy import array except: unittest.TestCase.skipTest(self, 'numpy is not installed') self.assertRaises(ValueError, lambda:model.heat_map_analysis(data=array([]), mask_width=56, mask_height=56, step_size=8, display=False))