<commit_before>import tensorflow as tf
import numpy as np

from foolbox.models import TensorFlowModel


def test_tensorflow_model():
    for nc in [10, 1000]:
        g = tf.Graph()
        with g.as_default():
            images = tf.placeholder(tf.float32, (None, 224, 224, 3))
            logits = tf.tile(
                tf.reduce_mean(
                    images,
                    axis=(1, 2, 3)
                )[..., np.newaxis],
                [1, nc])

        with tf.Session(graph=g):
            model = TensorFlowModel(images, logits, bounds=(0, 255))

            _images = np.random.rand(2, 224, 224, 3).astype(np.float32)
            _label = 22

            assert model.batch_predictions(_images).shape == (2, nc)

            _logits = model.predictions(_images[0])
            assert _logits.shape == (nc,)

            _gradient = model.gradient(_images[0], _label)
            assert _gradient.shape == _images[0].shape

            np.testing.assert_almost_equal(
                model.predictions_and_gradient(_images[0], _label)[0],
                _logits)
            np.testing.assert_almost_equal(
                model.predictions_and_gradient(_images[0], _label)[1],
                _gradient)

            assert model.num_classes() == nc
<commit_msg>changed label to be below 10<commit_after>import tensorflow as tf
import numpy as np

from foolbox.models import TensorFlowModel


def test_tensorflow_model():
    for nc in [10, 1000]:
        g = tf.Graph()
        with g.as_default():
            images = tf.placeholder(tf.float32, (None, 224, 224, 3))
            logits = tf.tile(
                tf.reduce_mean(
                    images,
                    axis=(1, 2, 3)
                )[..., np.newaxis],
                [1, nc])

        with tf.Session(graph=g):
            model = TensorFlowModel(images, logits, bounds=(0, 255))

            _images = np.random.rand(2, 224, 224, 3).astype(np.float32)
            _label = 7

            assert model.batch_predictions(_images).shape == (2, nc)

            _logits = model.predictions(_images[0])
            assert _logits.shape == (nc,)

            _gradient = model.gradient(_images[0], _label)
            assert _gradient.shape == _images[0].shape

            np.testing.assert_almost_equal(
                model.predictions_and_gradient(_images[0], _label)[0],
                _logits)
            np.testing.assert_almost_equal(
                model.predictions_and_gradient(_images[0], _label)[1],
                _gradient)

            assert model.num_classes() == nc

{'fraction_non_alphanumeric': 0.11274131274131274, 'fraction_numerical': 0.03359073359073359, 'mean_word_length': 1.7505307855626326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3002314', 'n_tokens_mistral': 847, 'n_tokens_neox': 735, 'n_words': 163}