mnist

解决Sklearn中使用数据集MNIST无法获取的问题(WinError 10060)

南笙酒味 提交于 2019-11-27 16:21:53
今天在学习PCA的时候,使用mnist数据集遇到一个问题,代码是这样的: 1 import numpy as np 2 from sklearn.datasets import fetch_mldata 3 4 mnist = fetch_mldata("MNIST original") 遇到了报错: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 原因: 以为是源地址被墙了,就搭梯子试试,结果还是不行 搜了一下原因,是因为源地址已经不能用了 解决办法: 使用本地数据集,可以从这下载: https://github.com/amplab/datascience-sp14/raw/master/lab7/mldata/mnist-original.mat 这个速度不快,可以使用我的百度云链接: 链接:https://pan.baidu.com/s/1NH1VSnX_Bkvr3k-Dku4gAw 提取码:herq 下载好后使用fetch_mldata的 data_home 参数指定文件所在目录 例如:   我的Jupyter文件在 F:\PyCharmWorkSpace\ML下,在其中新建一个datasets,并在代码中指定  mnist = fetch_mldata("MNIST original",data_home='.

How to convert a grayscale image into a list of pixel values?

百般思念 提交于 2019-11-27 15:24:04
问题 I am trying to create a python program which takes a grayscale, 24*24 pixel image file (I haven't decided on the type, so suggestions are welcome) and converts it to a list of pixel values from 0 (white) to 255 (black). I plan on using this array for creating a MNIST-like bytefile of the picture, that can be recognized by Tensor-Flow handwriting recognition algorithms. I have found the Pillow library to be the most useful in this task, by iterating over each pixel and appending its value to

Keras - Save image embedding of the mnist data set

谁说我不能喝 提交于 2019-11-27 15:03:26
问题 I've written the following simple MLP network for the MNIST db. from __future__ import print_function import keras from keras.datasets import mnist from keras.models import Sequential from keras.layers import Dense, Dropout from keras import callbacks batch_size = 100 num_classes = 10 epochs = 20 tb = callbacks.TensorBoard(log_dir='/Users/shlomi.shwartz/tensorflow/notebooks/logs/minist', histogram_freq=10, batch_size=32, write_graph=True, write_grads=True, write_images=True, embeddings_freq

pytorch之 CNN

送分小仙女□ 提交于 2019-11-27 14:51:37
1 # library 2 # standard library 3 import os 4 5 # third-party library 6 import torch 7 import torch.nn as nn 8 import torch.utils.data as Data 9 import torchvision 10 import matplotlib.pyplot as plt 11 12 # torch.manual_seed(1) # reproducible 13 14 # Hyper Parameters 15 EPOCH = 1 # train the training data n times, to save time, we just train 1 epoch 16 BATCH_SIZE = 50 17 LR = 0.001 # learning rate 18 DOWNLOAD_MNIST = False 19 20 21 # Mnist digits dataset 22 if not(os.path.exists('./mnist/')) or not os.listdir('./mnist/'): 23 # not mnist dir or mnist is empyt dir 24 DOWNLOAD_MNIST = True 25 26

fashion MNIST识别(Tensorflow + Keras + NN)

混江龙づ霸主 提交于 2019-11-27 14:10:15
Fashion MNIST https://www.kaggle.com/zalando-research/fashionmnist Fashion-MNIST is a dataset of Zalando's article images—consisting of a training set of 60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image, associated with a label from 10 classes. Zalando intends Fashion-MNIST to serve as a direct drop-in replacement for the original MNIST dataset for benchmarking machine learning algorithms. It shares the same image size and structure of training and testing splits. The original MNIST dataset contains a lot of handwritten digits. Members of the AI/ML

mnist 数据集的识别源码解析

故事扮演 提交于 2019-11-27 13:40:12
在基本跑完识别代码后,再来谈一谈自己对代码的理解; 1 前向传播过程文件(mnist_forward.py) 第一个函数get_weight(shape, regularizer); 定义了w的初值和正则化损失加入losses中 第二个函数get_bias(shape): 对参数b进行设定 第三个函数forward(x, regularizer): 加入激活函数tf.nn.relu(tf.matmul(x, w1) + b1) 对输出y进行设定 此段代码在前面博客中讲过,比较简单,就不再过多叙述 2 反向传播过程文件(mnist_backward.py) ce = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=y, labels=tf.argmax(y_, 1)) 在计算交叉熵之前,通常要用到softmax层来计算结果的概率分布。因为softmax层并不会改变最终的分类结果(排序),所以,tensorflow将softmax层与交叉熵函数进行封装,形成一个函数方便计算: tf.nn.softmax_cross_entropy_with_logits(logits= , labels=)。 为了加速计算过程,针对只有一个正确答案(例如MNIST识别)的分类问题 这里用到softmax()函数;可以参考我前面博文。地址:

RNN入门(一)识别MNIST数据集

微笑、不失礼 提交于 2019-11-27 13:39:48
RNN介绍   在读本文之前,读者应该对全连接神经网络(Fully Connected Neural Network, FCNN)和卷积神经网络( Convolutional Neural Network, CNN)有一定的了解。对于FCNN和CNN来说,他们能解决很多实际问题,但是它们都只能单独的取处理一个个的输入,前一个输入和后一个输入是完全没有关系的 。而在现实生活中,我们输入的向量往往存在着前后联系,即前一个输入和后一个输入是有关联的,比如文本,语音,视频等,因此,我们需要了解深度学习中的另一类重要的神经网络,那就是循环神经网络(Recurrent Neural Network,RNN).   循环神经网络(Recurrent Neural Network,RNN)依赖于一个重要的概念:序列(Sequence),即输入的向量是一个序列,存在着前后联系。简单RNN的结构示意图如下: 相比于之前的FCNN,RNN的结构中多出了一个自循环部分,即W所在的圆圈,这是RNN的精华所在,它展开后的结构如下: 对于t时刻的输出向量 \(o_{t}\) ,它的输出不仅仅依赖于t时刻的输入向量 \(x_{t}\) ,还依赖于t-1时刻的隐藏层向量 \(s_{t-1}\) ,以下是输出向量 \(o_{t}\) 的计算公式: \[s_{t}=f(Ux_{t}+Ws_{t-1})\] \[o_{t

RNN识别MNIST数据集

空扰寡人 提交于 2019-11-27 13:39:24
RNN介绍   在读本文之前,大家应该对全连接神经网络(Fully Connected Neural Network, FCNN)和卷积神经网络( Convolutional Neural Network, CNN)有一定的了解。对于FCNN和CNN来说,他们能解决很多实际问题,但是它们都只能单独的取处理一个个的输入,前一个输入和后一个输入是完全没有关系的 。而在现实生活中,我们输入的向量往往存在着前后联系,即前一个输入和后一个输入是有关联的,比如文本,语音,视频等,因此,我们需要了解深度学习中的另一类重要的神经网络,那就是循环神经网络(Recurrent Neural Network,RNN).   循环神经网络(Recurrent Neural Network,RNN)依赖于一个重要的概念:序列(Sequence),即输入的向量是一个序列,存在着前后联系。简单RNN的结构示意图如下: 简单RNN的结构示意图   相比于之前的FCNN,RNN的结构中多出了一个自循环部分,即W所在的圆圈,这是RNN的精华所在,它展开后的结构如下: RNN展开后的结构   对于t时刻的输出向量 ,它的输出不仅仅依赖于t时刻的输入向量 ,还依赖于t-1时刻的隐藏层向量 ,以下是输出向量 的计算公式:   其中,第二个式子为输出层的计算公式,输出层为全连接层,V为权重矩阵,g为激活函数。第一个式子中

GAN

女生的网名这么多〃 提交于 2019-11-27 09:58:07
GAN,MNIST生成数字 import os import matplotlib.pyplot as plt import itertools import pickle import imageio import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torchvision import datasets, transforms from torch.autograd import Variable import numpy as np # G(z) class generator(nn.Module): # initializers def __init__(self, input_size=32, n_class = 10): super(generator, self).__init__() self.fc1 = nn.Linear(input_size, 256) self.fc2 = nn.Linear(self.fc1.out_features, 512) self.fc3 = nn.Linear(self.fc2.out_features, 1024) self.fc4 = nn.Linear(self.fc3.out

Eager Execution

谁说胖子不能爱 提交于 2019-11-27 08:47:54
  Tensorflow的Eager Execution是一种命令编程环境, 操作会返回具体的值。   要启动Eager Execution,请将tf.enable_eager_execution()添加到程序或控制台回话的开头。   启用Eager Execution会改变TensorFlow操作的行为方式,现在他们会 立即评估并将值返回给Python 。tf.Tensor对象会引用具体值,而不是指向计算图中的节点的符号句柄。由于不需要构建稍后在会话中运行的计算图,因此使用print()或调试程序很容易检查结果。评估、输出和检查张量值不会中断计算梯度的流程。   tf.Tensor与numpy ndarray可以互相转换。 动态控制流:   在执行模型时,主机语言的所有功能都可用。 构建模型   将TensorFlow与Eager与Eager Execution结合使用时,可以编写自己的层或使用在tf.keras.layers程序包中提供的层。   虽然可以使用任何Python对象表示层,但TensorFlow提供了便利的基类tf.karas.layers.Layer。可以通过他实现自己的层: class MysimpleLayer(tf.keras.layers.Layer): def __init__(self,output_units): super