def _image_dl_estimator(one_classifier=False, functional=False, **kwargs): sess = None wildcard = False classifier_list = None if kwargs.get("wildcard") is not None: if kwargs.get("wildcard") is True: wildcard = True del kwargs["wildcard"] if framework == "keras": if wildcard is False and functional is False: if functional: classifier_list = [ get_image_classifier_kr_functional(**kwargs) ] else: classifier_list = [get_image_classifier_kr(**kwargs)] if framework == "tensorflow": if wildcard is False and functional is False: classifier, sess = get_image_classifier_tf(**kwargs) classifier_list = [classifier] if framework == "pytorch": if wildcard is False and functional is False: classifier_list = [get_image_classifier_pt(**kwargs)] if framework == "scikitlearn": logging.warning( "{0} doesn't have an image classifier defined yet".format( framework)) classifier_list = None if framework == "kerastf": if wildcard: classifier_list = [ get_image_classifier_kr_tf_with_wildcard(**kwargs) ] else: if functional: classifier_list = [ get_image_classifier_kr_tf_functional(**kwargs) ] else: classifier_list = [get_image_classifier_kr_tf(**kwargs)] if framework == "mxnet": if wildcard is False and functional is False: classifier_list = [get_image_classifier_mx_instance(**kwargs)] if classifier_list is None: return None, None if one_classifier: return classifier_list[0], sess return classifier_list, sess
def test_loss_gradient_with_wildcard(self): classifier = get_image_classifier_kr_tf_with_wildcard() # Test gradient shapes = [(1, 10, 1), (1, 20, 1)] for shape in shapes: x = np.random.normal(size=shape) loss_gradient = classifier.loss_gradient(x, y=[1]) self.assertEqual(loss_gradient.shape, shape) class_gradient = classifier.class_gradient(x, 0) self.assertEqual(class_gradient[0].shape, shape)
def _image_dl_estimator(functional=False, **kwargs): sess = None wildcard = False classifier = None if kwargs.get("wildcard") is not None: if kwargs.get("wildcard") is True: wildcard = True del kwargs["wildcard"] if framework == "keras": if wildcard is False and functional is False: if functional: classifier = get_image_classifier_kr_functional(**kwargs) else: try: classifier = get_image_classifier_kr(**kwargs) except NotImplementedError: raise ARTTestFixtureNotImplemented( "This combination of loss function options is currently not supported.", image_dl_estimator.__name__, framework, ) if framework == "tensorflow1" or framework == "tensorflow2": if wildcard is False and functional is False: classifier, sess = get_image_classifier_tf(**kwargs) return classifier, sess if framework == "pytorch": if not wildcard: if functional: classifier = get_image_classifier_pt_functional(**kwargs) else: classifier = get_image_classifier_pt(**kwargs) if framework == "kerastf": if wildcard: classifier = get_image_classifier_kr_tf_with_wildcard(**kwargs) else: if functional: classifier = get_image_classifier_kr_tf_functional( **kwargs) else: classifier = get_image_classifier_kr_tf(**kwargs) if framework == "mxnet": if wildcard is False and functional is False: classifier = get_image_classifier_mx_instance(**kwargs) if classifier is None: raise ARTTestFixtureNotImplemented( "no test deep learning estimator available", image_dl_estimator.__name__, framework) return classifier, sess