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_object_table_3(self): if self.data_dir_local is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR_LOCAL 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)) captions_file = self.data_dir_local + 'image_captions.txt' image_table = create_captions_table(self.s, captions_file) word_embeddings = self.data_dir + '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') self.assertRaises( DLPyError, lambda: create_embeddings_from_object_detection( self.s, image_table, detection_model, word_embeddings))
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_resnet50_caffe(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 + 'ResNet-50-model.caffemodel.h5' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest(self, "File, {}, not found.".format(file_dependency)) model = ResNet50_Caffe(self.s, n_channels=3, height=224, random_flip='HV', pre_trained_weights_file=self.data_dir + 'ResNet-50-model.caffemodel.h5', pre_trained_weights=True, include_top=False, n_classes=120, random_crop='unique') model.print_summary() model = ResNet50_Caffe(self.s, n_channels=3, height=224, random_flip='HV', pre_trained_weights_file=self.data_dir + 'ResNet-50-model.caffemodel.h5', pre_trained_weights=True, include_top=False, n_classes=120, random_crop=None, offsets=None) model.print_summary() # test random_mutation and crop on VDMML 8.4 model = ResNet50_Caffe(self.s, n_channels=3, height=224, random_flip='HV', pre_trained_weights_file=self.data_dir + 'ResNet-50-model.caffemodel.h5', pre_trained_weights=True, include_top=False, n_classes=120, random_crop='RESIZETHENCROP', random_mutation='random', offsets=None)
def test_inceptionv3_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 + 'InceptionV3_weights.kerasmodel.h5' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest(self, "File, {}, not found.".format(file_dependency)) from dlpy.applications import InceptionV3 model = InceptionV3(self.s, model_table='INCEPTIONV3', n_classes=1000, n_channels=3, width=299, height=299, scale=1, offsets=(103.939, 116.779, 123.68), pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'InceptionV3_weights.kerasmodel.h5', include_top=True) model.print_summary() # test random_crop and mutation model2 = InceptionV3(self.s, model_table='VGG16', n_classes=1000, n_channels=3, width=299, height=299, scale=1, offsets=None, random_crop='unique', random_flip='hv', random_mutation='random', pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'InceptionV3_weights.kerasmodel.h5', include_top=True) model2.print_summary()
def test_resnet50_3(self): from dlpy.applications import ResNet50_Caffe 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 + 'ResNet-50-model.caffemodel.h5' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest(self, "File, {}, not found.".format(file_dependency)) reshape = Reshape(width=224, height=224, depth=3, order='WHD') model = ResNet50_Caffe(self.s, reshape_after_input=reshape) model.print_summary() # test it with pretrained weights model1 = ResNet50_Caffe(self.s, model_table='Resnet50', n_classes=1000, n_channels=3, width=224, height=224, scale=1, offsets=None, random_crop='unique', random_flip='hv', random_mutation='random', pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'ResNet-50-model.caffemodel.h5', include_top=True, reshape_after_input=reshape) res = model1.print_summary() print(res) self.assertEqual(res.iloc[1, 6][0], 224) self.assertEqual(res.iloc[1, 6][1], 224) self.assertEqual(res.iloc[1, 6][2], 3)
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") 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') 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_densenet121_onnx_2(self): from dlpy.applications import DenseNet121_ONNX 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 + 'DenseNet121_ONNX.sashdat' if not file_exist_on_server(self.s, file_dependency): unittest.TestCase.skipTest(self, "File, {}, not found.".format(file_dependency)) model = DenseNet121_ONNX(self.s, model_file=file_dependency, width=224, height=224, n_classes=1000, include_top=True) model.print_summary()
def test_vgg16_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)) model1 = VGG16(self.s, model_table='VGG16', n_classes=1000, n_channels=3, width=224, height=224, scale=1, offsets=(103.939, 116.779, 123.68), pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5', include_top=True) model1.print_summary() model2 = VGG16(self.s, model_table='VGG16', n_classes=1000, n_channels=3, width=224, height=224, scale=1, offsets=None, random_crop=None, pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5', include_top=True) model2.print_summary() self.assertRaises(ValueError, lambda: VGG16(self.s, model_table='VGG16', n_classes=1000, n_channels=3, width=224, height=224, scale=1, offsets=None, random_crop='wrong_val', pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5', include_top=True)) # test random_crop and mutation model3 = VGG16(self.s, model_table='VGG16', n_classes=1000, n_channels=3, width=224, height=224, scale=1, offsets=None, random_crop='unique', random_flip='hv', random_mutation='random', pre_trained_weights=True, pre_trained_weights_file=self.data_dir + 'VGG_ILSVRC_16_layers.caffemodel.h5', include_top=True) model3.print_summary()
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))