def binarized2_bn_label(): image = bn_image() image = binarize(image, (0, 1), included_in='lower') mean = np.mean(image, axis=(0, 1)) assert mean.shape == (10,) label = np.argmax(mean) return label
def binarized_bn_label(bn_image): image = bn_image image = binarize(image, (0, 1)) mean = np.mean(image, axis=(0, 1)) assert mean.shape == (10,) label = np.argmax(mean) return label
def preprocessing(x): x = binarize(x, (0, 1), included_in='lower') def backward(x): return x return x, backward
def preprocessing(x): x = binarize(x, (0, 1)) def backward(x): return x return x, backward
def binarized2_bn_labels(bn_images): images = bn_images images = binarize(images, (0, 1), included_in="lower") means = np.mean(images, axis=(1, 2)) assert means.shape == (len(images), 10) labels = np.argmax(means, -1) return labels
def binarized_bn_labels(bn_images): images = bn_images images = binarize(images, (1, 2)) means = np.mean(images, axis=(1, 2)) assert means.shape == (len(bn_images), 10) label = np.argmax(means, axis=-1) return label
def test_binarize(): x = np.array([0.1, 0.5, 0.7, 0.4]) x1 = binarize(x, (-2, 2), 0.5) assert np.all(abs(x1) == 2) with pytest.raises(ValueError): binarize(x, (-2, 2), 0.5, included_in='blabla')