<jupyter_start><jupyter_text>MNIST 手写数字图片集 载入 mnist 数据集， 并将图片转为 Theano 的图片格式。<jupyter_code>(X_train, y_train), (X_test, y_test) = mnist.load_data()

# reshape is needed for the Theano backend 
X_train = X_train.reshape(X_train.shape[0], 1, 28, 28)
X_train = X_train.astype('float32')<jupyter_output><empty_output><jupyter_text>绘图函数，通过设置 *batch_size=9* 让 ImageDataGenerator 每个批次返回9张图片。ImageDataGenerator 默认会打散图片序列， *shuffle=False* 这样多次运行，  让。<jupyter_code>def plot_digits(gen):
    gen.fit(X_train)
    for X_batch, y_batch in gen.flow(X_train, y_train, batch_size=9, shuffle=False, seed=42):
        for i in range(0, 9):
            plt.subplot(330 + 1 + i)
            plt.imshow(X_batch[i].reshape(28, 28))
        plt.show()
        break<jupyter_output><empty_output><jupyter_text>首先让我们看看未经处理的图片是张什么样的？<jupyter_code>gen=plot_digits(ImageDataGenerator())<jupyter_output><empty_output><jupyter_text>水平和垂直翻转*horizontal_flip* 和 *vertical_flip* 这两个参数控制是否*随机*对某些图片进行水平和处置方向上的翻转<jupyter_code>plot_digits(ImageDataGenerator(horizontal_flip=True))
plot_digits(ImageDataGenerator(vertical_flip=True))<jupyter_output><empty_output><jupyter_text>旋转<jupyter_code>plot_digits(ImageDataGenerator(rotation_range=60))
plot_digits(ImageDataGenerator(width_shift_range=0.3))
plot_digits(ImageDataGenerator(height_shift_range=0.3))
plot_digits(ImageDataGenerator(shear_range=np.pi))
plot_digits(ImageDataGenerator(zoom_range=1))<jupyter_output><empty_output><jupyter_text>fill_mode 填充模式<jupyter_code>plot_digits(ImageDataGenerator(zoom_range=2, fill_mode="nearest"))
plot_digits(ImageDataGenerator(zoom_range=2, fill_mode="reflect"))
plot_digits(ImageDataGenerator(zoom_range=2, fill_mode="wrap"))
plot_digits(ImageDataGenerator(zoom_range=2, cval=255, fill_mode="constant"))
plot_digits(ImageDataGenerator(zca_whitening=True))<jupyter_output><empty_output><jupyter_text>Dog vs Cat<jupyter_code>%cd data/dogscats/
import os
gen = ImageDataGenerator()
X_fit_batch, y_fit_batch =gen.flow_from_directory('train', batch_size=500, shuffle=False, seed=42).next()
def plot_cats(gen):
    gen.fit(X_fit_batch)
    for X_batch, y_batch in gen.flow_from_directory('train', batch_size=9, shuffle=True, seed=42):
        for i in range(0, 9):
            plt.subplot(3, 3, 1 + i)
            plt.imshow(X_batch[i].transpose(1, 2, 0).astype(np.uint8))
        plt.show()
        break

plot_cats(ImageDataGenerator())
plot_cats(ImageDataGenerator(channel_shift_range=100))
plot_cats(ImageDataGenerator(featurewise_center=True))
plot_cats(ImageDataGenerator(samplewise_center=True))
plot_cats(ImageDataGenerator(featurewise_std_normalization=True))
plot_cats(ImageDataGenerator(samplewise_std_normalization=True))<jupyter_output>Found 23000 images belonging to 2 classes.
{'fraction_non_alphanumeric': 0.11925601750547046, 'fraction_numerical': 0.022975929978118162, 'mean_word_length': 8.974545454545455, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '106759', 'license': 'Apache-2.0', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1139, 'n_words': 125, 'path': 'deeplearning1/nbs/Keras ImageDataGenerator.ipynb', 'repo_name': 'glasslion/fastai-courses', 'size': '2742'}