from math import ceil import pytest import numpy as np from numpy.testing import assert_allclose from numpy.testing import assert_equal from numpy.testing import assert_raises import keras # TODO: remove the 3 lines below once the Keras release # is configured to use keras_preprocessing import keras_preprocessing keras_preprocessing.set_keras_submodules( backend=keras.backend, utils=keras.utils) from keras_preprocessing import sequence def test_pad_sequences(): a = [[1], [1, 2], [1, 2, 3]] # test padding b = sequence.pad_sequences(a, maxlen=3, padding='pre') assert_allclose(b, [[0, 0, 1], [0, 1, 2], [1, 2, 3]]) b = sequence.pad_sequences(a, maxlen=3, padding='post') assert_allclose(b, [[1, 0, 0], [1, 2, 0], [1, 2, 3]]) # test truncating b = sequence.pad_sequences(a, maxlen=2, truncating='pre') assert_allclose(b, [[0, 1], [1, 2], [2, 3]]) b = sequence.pad_sequences(a, maxlen=2, truncating='post')
import pytest from PIL import Image import numpy as np import os import tempfile import shutil import keras import pandas as pd import random # TODO: remove the 3 lines below once the Keras release # is configured to use keras_preprocessing import keras_preprocessing keras_preprocessing.set_keras_submodules( backend=keras.backend, utils=keras.utils) # This enables this import from keras_preprocessing import image class TestImage(object): def setup_class(cls): cls.img_w = cls.img_h = 20 rgb_images = [] rgba_images = [] gray_images = [] for n in range(8): bias = np.random.rand(cls.img_w, cls.img_h, 1) * 64 variance = np.random.rand(cls.img_w, cls.img_h, 1) * (255 - 64) imarray = np.random.rand(cls.img_w, cls.img_h, 3) * variance + bias