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_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 find_object_by_color(conn, detection_table_long, object_color_table, output_table, object_name, object_color, color_cluster_min_size=0, object_column='OBJECT_NAME', color_column='COLOR_NAME', color_cluster_size_column='COLOR_CLUSTER_PERCENT', id_column='_LABEL_', replace=True): conn.loadactionset('fedSql') #object_ids = object_color_table[object_color_table[color_column] == object_color][id_column].values object_ids = object_color_table[ (object_color_table[color_column] == object_color) & (object_color_table[color_cluster_size_column] > color_cluster_min_size)][id_column].values object_ids = "', '".join(object_ids) object_ids = "('{}')".format(object_ids) conn.loadactionset('fedSql') if replace == True: replace_option = "{options replace=true}" else: replace_option = "{options replace=false}" query = ' create table {} {} as '.format(output_table, replace_option) query += " select * from {} ".format(detection_table_long.name) query += " where {} = \'{}\' and {} in {} ".format(object_column, object_name, id_column, object_ids) res = conn.fedSql.execDirect(query=query) img_tbl = ImageTable.from_table(conn.CASTable(output_table)) return img_tbl
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_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 setUp(self): swat.reset_option() swat.options.cas.print_messages = False swat.options.interactive_mode = False self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL) if type(self).server_type is None: # Set once per class and have every test use it. No need to change between tests. type(self).server_type = tm.get_cas_host_type(self.s) self.srcLib = tm.get_casout_lib(self.server_type) filename = os.path.join(os.path.dirname(__file__), 'datasources', 'ImageData.sashdat') r = tm.load_data(self.s, filename, self.server_type) self.tablename = r['tableName'] self.assertNotEqual(self.tablename, None) self.table = ImageTable.from_table(r['casTable'])
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))