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_resnet50_3(self): from dlpy.applications import ResNet50_Caffe 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_resnet50_caffe_caslib_msg(self): if self.data_dir is None: unittest.TestCase.skipTest( self, "DLPY_DATA_DIR is not set in the environment variables") model = ResNet50_Caffe(self.s, n_channels=3, height=224, random_flip='HV', pre_trained_weights_file=self.data_dir + 'data/ResNet-50-model.caffemodel.h5', pre_trained_weights=True, include_top=False, n_classes=120, random_crop='unique') 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()
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_resnet50_4(self): from dlpy.applications import ResNet50_Caffe reshape = Pooling(width=2, height=2, stride=2) self.assertRaises( DLPyError, lambda: ResNet50_Caffe(self.s, reshape_after_input=reshape))
def test_resnet50_layerid(self): if self.data_dir is None: unittest.TestCase.skipTest(self, "DLPY_DATA_DIR is not set in the environment variables") model = ResNet50_Caffe(self.s) model.print_summary() model.print_summary()
def test_mix_cnn_rnn_network(self): from dlpy.applications import ResNet50_Caffe from dlpy import Sequential from dlpy.blocks import Bidirectional # the case is to test if CNN and RNN model can be connect using functional api # the model_type is expected to be RNN in 19w47. # CNN model = ResNet50_Caffe(self.s) cnn_head = model.to_functional_model(stop_layers = model.layers[-1]) # RNN model_rnn = Sequential(conn = self.s, model_table = 'rnn') model_rnn.add(Bidirectional(n = 100, n_blocks = 2)) model_rnn.add(OutputLayer('fixed')) f_rnn = model_rnn.to_functional_model() # connecting inp = Input(**cnn_head.layers[0].config) x = cnn_head(inp) y = f_rnn(x) cnn_rnn = Model(self.s, inp, y) cnn_rnn.compile() # check type self.assertTrue(cnn_rnn.model_type == 'RNN') self.assertTrue(cnn_rnn.layers[-1].name == 'fixed') self.assertTrue(x[0].shape == (1, 1, 2048)) f_rnn = model_rnn.to_functional_model() # connecting inp = Input(**cnn_head.layers[0].config) x = cnn_head(inp) y = f_rnn(x) cnn_rnn = Model(self.s, inp, y) cnn_rnn.compile() # it should be fixed if I create f_rnn again. self.assertTrue(cnn_rnn.layers[-1].name == 'fixed') inp = Input(**cnn_head.layers[0].config) x = cnn_head(inp) y = f_rnn(x) cnn_rnn = Model(self.s, inp, y) cnn_rnn.compile() # it should be fixed if I create f_rnn again. self.assertTrue(cnn_rnn.layers[-1].name == 'fixed_2')
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))
def test_resnet50_2(self): from dlpy.applications import ResNet50_Caffe model = ResNet50_Caffe(self.s) model.print_summary()
def test_multiple_stop_layers1(self): from dlpy.applications import ResNet50_Caffe resnet50 = ResNet50_Caffe(self.s, "res50") stop_layers = [resnet50.layers[x] for x in [-2, 4, -8] ] feature_extractor1 = resnet50.to_functional_model(stop_layers=stop_layers)