fashion-mnist简介和使用及下载

这个数据集是我们国家的一个大佬制作的,还发表了论文:Fashion-MNIST: a Novel Image Dataset for Benchmarking Machine Learning Algorithms
GitHub地址:https://github.com/zalandoresearch/fashion-mnist
数据集以及论文打包上传了:数据集和论文
数据集的内容是这样的:


其中值得我们关注的是数据制作的方法:
最原始图片是背景为浅灰色的,分辨率为762*1000 的JPEG图片。然后经过resampled 到 51*73 的彩色图片。然后依次经过以下7个步骤,最终得到28*28的灰度图

  1. JPEG –> PNG
  2. 裁剪背景
  3. 按比例: max(h,w)28max(h,w)28 将图像缩放,也就是将一个维度缩放至28
  4. 锐化
  5. 再扩充至28*28,再把object调整至图片中央
  6. 将负的像素点剔除
  7. 转化成28*28的灰度图

简单的使用例子:
import  tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data

fashion = input_data.read_data_sets('data/fashion', one_hot=True)

print(fashion.train.images.shape)
print(fashion.train.labels.shape)

batch_size = 100
batch_num = fashion.train.num_examples // batch_size

#定义X,Y参数
x = tf.placeholder(tf.float32, shape=[None, 784])
y = tf.placeholder(tf.float32, shape=[None, 10])
#定义W,B参数
W = tf.Variable(tf.truncated_normal([784, 10], stddev= 0.1))
b = tf.Variable(tf.zeros([10]) + 0.1)

#预测结果
prediction = tf.nn.softmax(tf.matmul(x, W) + b)
#使用交叉熵计算loss
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=prediction, labels=y))
#定义优化器
train_step = tf.train.GradientDescentOptimizer(0.2).minimize(cross_entropy)
#判断预测结果是否正确
correct_prediction = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1))
#计算准确率,将bool值转为float32
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    for epoch in range(21):
        for i in range(batch_num):
            batch_xs, batch_ys = fashion.train.next_batch(batch_size)
            sess.run(train_step, feed_dict={x: batch_xs, y:batch_ys})
        acc = sess.run(accuracy, feed_dict={x:fashion.test.images, y:fashion.test.labels})
        print('Epoch: '+str(epoch)+',acc: '+str(acc))

猜你喜欢

转载自blog.csdn.net/qq_36387683/article/details/80612627