25-Mnist03

部署运行你感兴趣的模型镜像
from tensorflow.examples.tutorials.mnist.input_data import read_data_sets
import numpy as np
import cv2
import tensorflow as tf


class Config:
    def __init__(self):
        self.sample_path = '../deeplearning_ai12/p07_mnist/MNIST_data'
        self.lr = 0.001


class Tensors:
    def __init__(self, config):
        self.x = tf.placeholder(tf.float32, [None, 784], 'x')
        logits = self.get_logits()  # [-1, 10]
        p = tf.nn.softmax(logits)   # [-1, 10]

        self.y = tf.placeholder(tf.int32, [None], 'y')
        y = tf.one_hot(self.y, 10)  # [-1, 10]

        self.loss = -tf.reduce_mean(tf.reduce_sum(y * tf.log(p)))
        opt = tf.train.AdamOptimizer(config.lr)
        self.train_op = opt.minimize(self.loss)


class Samples:
    def __init__(self, config):
        ds = read_data_sets(config.sample_path)
        print(ds.train.num_examples)
        print(ds.validation.num_examples)
        print(ds.test.num_examples)

        xs, ys = ds.train.next_batch(200)
        # xs: [200, 784]
        # ys: [200]

        print(ys)
        xs = np.reshape(xs, [-1, 28, 28])
        xs = np.transpose(xs, [1, 0, 2])  # [28, -1, 28]
        xs = np.reshape(xs, [28, -1, 28 * 20])  # [28, -1, 560],
        xs = np.transpose(xs, [1, 0, 2])  # [-1, 28, 560]
        xs = np.reshape(xs, [-1, 28 * 20])

        cv2.imshow('My digits', xs)
        cv2.waitKey()


class App:
    def __init__(self, config):
        self.samples = Samples(config)
        self.tensors = Tensors(config)

    def train(self):
        pass


if __name__ == '__main__':
    config = Config()
    app = App(config)

    app.train()

D:\Anaconda\python.exe D:/AI20/HJZ/05-深度学习项目/deeplearning_20/p25_mnist/mnist03.py
WARNING:tensorflow:From D:/AI20/HJZ/05-深度学习项目/deeplearning_20/p25_mnist/mnist03.py:29: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.
WARNING:tensorflow:From D:\Anaconda\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Please write your own downloading logic.
WARNING:tensorflow:From D:\Anaconda\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting ../deeplearning_ai12/p07_mnist/MNIST_data\train-images-idx3-ubyte.gz
Extracting ../deeplearning_ai12/p07_mnist/MNIST_data\train-labels-idx1-ubyte.gz
Extracting ../deeplearning_ai12/p07_mnist/MNIST_data\t10k-images-idx3-ubyte.gz
WARNING:tensorflow:From D:\Anaconda\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting ../deeplearning_ai12/p07_mnist/MNIST_data\t10k-labels-idx1-ubyte.gz
WARNING:tensorflow:From D:\Anaconda\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py:290: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.
55000
5000
10000
[4 7 9 0 0 8 6 3 0 5 4 6 2 5 6 8 7 3 0 9 3 8 0 3 3 1 3 1 3 7 1 9 8 0 1 9 4
 7 8 2 3 2 6 0 1 5 6 9 1 8 1 7 3 8 7 1 5 2 3 9 7 4 9 4 7 4 9 1 1 2 3 2 9 0
 7 3 5 9 9 4 9 2 2 5 3 9 7 5 4 9 5 4 3 2 4 2 7 8 5 5 6 0 1 8 0 9 2 9 2 8 4
 4 5 3 9 2 7 5 2 5 0 8 1 1 7 8 4 8 9 3 1 0 7 7 6 0 6 7 8 5 3 7 5 8 7 8 4 4
 7 4 5 3 6 7 1 3 6 5 5 3 3 6 9 3 4 1 5 1 8 2 4 5 4 2 8 7 0 8 1 3 3 7 1 8 6
 6 9 1 7 2 1 6 5 8 6 1 4 8 6 0]

在这里插入图片描述

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.15

TensorFlow-v2.15

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值