# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + pycharm={"is_executing": false}
from tensorflow.examples.tutorials.mnist import input_data
from PIL import Image
import matplotlib.image
import os

# + pycharm={"name": "#%%\n", "is_executing": false}
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)

# + pycharm={"name": "#%%\n", "is_executing": false}
save_dir = "MNIST_data/raw/"
if os.path.exists(save_dir) is False:
    os.makedirs(save_dir)

# + pycharm={"name": "#%%\n", "is_executing": false}
# 保存前面的20张图片
for i in range(20):
    image_array = mnist.train.images[i, :].reshape(28, 28)
    filename = save_dir+'mnist_train_%d.jpg' % i
    matplotlib.image.imsave(filename, image_array, vmin=0.0, vmax=1.0)

# + pycharm={"name": "#%%\n"}



StarcoderdataJupyterScriptsDedupFiltered