mnist

How do I load in the MNIST digits and label data in MATLAB?

牧云@^-^@ 提交于 2019-12-06 14:13:02
I am trying to run the code given in the link https://github.com/bd622/DiscretHashing Discrete Hashing is a method for dimensionality reduction that is used on approximate nearest neighbor search. I want to load in the implementation on the MNIST database that is available in http://yann.lecun.com/exdb/mnist/ . I have extracted the files from their compressed gz format. PROBLEM 1 : Using the solution to read MNIST database provided in Reading MNIST Image Database binary file in MATLAB I am getting the following error: Error using fread Invalid file identifier. Use fopen to generate a valid

Tensorflow ValueError: Too many vaues to unpack (expected 2)

允我心安 提交于 2019-12-06 13:52:56
I have looked this up on Reddit, Stack Overflow, tech forums, documentation, GitHub issues etc etc and still can't solve this issue. For reference, I am using Python 3 TensorFlow on Windows 10, 64 Bit. I am trying to use my own dataset (300 pics of cats, 512x512, .png format) in Tensorflow to train it to know what a cat looks like. If this works I will train it with other animals and eventually objects. I can't seem to figure out why I am getting the error ValueError: too many values to unpack (expected 2) . The error appears in the line images,labal = create_batches(10) , which points to my

How to get the same loss value, every time training a CNN (MNIST data set), with TensorFlow?

十年热恋 提交于 2019-12-06 13:18:42
问题 I want to train a convolutional neural network (with MNIST data set and TensorFlow) a few times new and get every time the same results of the accuracy. To get this i: Save an untrained only initialized (global_variables_initializer) net Load every time I start the training this untrained net Set mnist.train.next_batch shuffle=False, so the image sequence is every time the same I have done this before with a feed forward net (3 hidden layer) and every time I run this python script I get the

center of mass of pixels in grayscale image

China☆狼群 提交于 2019-12-06 08:32:48
I'm working on a program that lets the user draw a digit in a "scribbling area" and with the press of a button the application will predict the digit that he entered, using a neural net classifier. Now, to train the neural net, I used MNIST database which specifies the following: "images from NIST were size normalized to fit in a 20x20 pixel box while preserving their aspect ratio [...] the images were centered in a 28 x 28 image by computing the center of mass of the pixels". The problem that I'm facing is that after resizing the digit that the user drew in the scribbling area to a size of 20

Python Numpy Error: ValueError: setting an array element with a sequence

落爺英雄遲暮 提交于 2019-12-06 03:00:00
I am trying to build a dataset similar to mnist.pkl.gz provided in theano logistic_sgd.py implementation. Following is my code snippet. import numpy as np import csv from PIL import Image import gzip, cPickle import theano from theano import tensor as T def load_dir_data(csv_file=""): print(" reading: %s" %csv_file) dataset=[] labels=[] cr=csv.reader(open(csv_file,"rb")) for row in cr: print row[0], row[1] try: image=Image.open(row[0]+'.jpg').convert('LA') pixels=[f[0] for f in list(image.getdata())] dataset.append(pixels) labels.append(row[1]) del image except: print("image not found") ret

模型蒸馏(Distil)及mnist实践

假如想象 提交于 2019-12-05 23:44:21
结论:蒸馏是个好方法。 模型压缩/蒸馏在论文《Model Compression》及《Distilling the Knowledge in a Neural Network》提及,下面介绍后者及使用keras测试mnist数据集。 蒸馏:使用小模型模拟大模型的泛性。 通常,我们训练mnist时,target是分类标签,在蒸馏模型时,使用的是教师模型的输出概率分布作为“soft target”。也即损失为学生网络与教师网络输出的交叉熵(这里采用DistilBert论文中的策略,此论文不同)。 当训练好教师网络后,我们可以不再需要分类标签,只需要比较2个网络的输出概率分布。当然可以在损失里再加上学生网络的分类损失,论文也提到可以进一步优化。 如图,将softmax公式稍微变换一下,目的是使得输出更小,softmax后就更为平滑。 论文的损失定义 本文代码使用的损失为p和q的交叉熵 代码测试部分 1,教师网络,测试精度99.46%,已经相当好了,可训练参数858,618。 # 教师网络 inputs=Input((28,28,1)) x=Conv2D(64,3)(inputs) x=BatchNormalization(center=True,scale=False)(x) x=Activation('relu')(x) x=Conv2D(64,3,strides=2)(x) x

将mnist数据集存储到本地文件

时光毁灭记忆、已成空白 提交于 2019-12-05 22:37:32
参考文章: http://www.csuldw.com/2016/02/25/2016-02-25-machine-learning-MNIST-dataset/ import numpy as np import struct import matplotlib.pyplot as plt import os filename = 'data_AI/MNIST/train-images.idx3-ubyte' binfile = open(filename , 'rb') buf = binfile.read() index = 0 magic, numImages , numRows , numColumns = struct.unpack_from('>IIII' , buf , index) index += struct.calcsize('IIII' ) images = [] for i in range(numImages): imgVal = struct.unpack_from('>784B', buf, index) index += struct.calcsize('>784B') imgVal = list(imgVal) for j in range(len(imgVal)): if imgVal[j] > 1: imgVal[j] = 1 images

Pytorch实现MNIST(附SGD、Adam、AdaBound不同优化器下的训练比较) adabound实现

╄→尐↘猪︶ㄣ 提交于 2019-12-05 21:44:49
 学习工具最快的方法就是在使用的过程中学习,也就是在工作中(解决实际问题中)学习。文章结尾处附完整代码。 一、数据准备   在Pytorch中提供了MNIST的数据,因此我们只需要使用Pytorch提供的数据即可。 from torchvision import datasets, transforms # batch_size 是指每次送入网络进行训练的数据量 batch_size = 64 # MNIST Dataset # MNIST数据集已经集成在pytorch datasets中,可以直接调用 train_dataset = datasets.MNIST(root='./data/', train=True, transform=transforms.ToTensor(), download=True) test_dataset = datasets.MNIST(root='./data/', train=False, transform=transforms.ToTensor()) train_loader = torch.utils.data.DataLoader(dataset=train_dataset, batch_size=batch_size, shuffle=True) test_loader = torch.utils.data.DataLoader

TensorFlow estimator number of classes does not change

筅森魡賤 提交于 2019-12-05 18:50:41
I tried using tensorflow estimator for the MNIST dataset. For some reason it keep saying my n_classes is set to 1 even though it is at 10! import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/",one_hot=True) feature_columns = [tf.feature_column.numeric_column("x", shape=[784])] # Build 3 layer DNN with 10, 20, 10 units respectively. classifier = tf.estimator.DNNClassifier(feature_columns=feature_columns, hidden_units=[500, 500, 500], n_classes=10, model_dir="/tmp/MT") for i in range(100000): xdata,

SGD与Adam识别MNIST数据集

我与影子孤独终老i 提交于 2019-12-05 15:19:42
几种常见的优化函数比较: https://blog.csdn.net/w113691/article/details/82631097 1 ''' 2 基于Adam识别MNIST数据集 3 ''' 4 import torch 5 import torchvision 6 import torchvision.transforms as transform 7 import torch.nn 8 from torch.autograd import Variable 9 10 ''' 11 神经网络层级结构: 12 卷积层Conv1,Conv2() 13 最大池化层 MaxPool2d() 14 损失函数 ReLU() 15 参数: 16 卷积神经网络的卷积层参数:------输入通道数、输出通道数、卷积核大小、卷积核移动步长和Padding的值 17 Conv2d(input_channels,output_channels,kernel_size,stride,padding); 18 最大池化层参数:------池化窗口大小、移动步长 19 MaxPool2d(kernel_size,stride) 20 方法: 21 1.torch.nn.Sequential()用作参数序列化,神经网络模块会按照传入Suquential构造器顺序依次被添加到计算图中执行 22 2