Path: blob/master/Convolutional Neural Networks/dummy/__pycache__/input_data.cpython-36.pyc
15917 views
3 �߱Yh � @ s� d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl Z ddl mZ ddl mZ ddlZ dZd d � Zdd� Zd d� Zddd�Zddd�ZG dd� de�Zdde jfdd�ZdS )z1Functions for downloading and reading MNIST data.� )�absolute_import)�division)�print_functionN)�urllib)�xrangez!http://yann.lecun.com/exdb/mnist/c C sd t jj|�st j|� t jj|| �}t jj|�s`tjjt| |�\}}t j |�}t d| |jd� |S )z@Download the data from Yann's website, unless it's already here.zSuccessfully downloadedzbytes.)�os�path�exists�mkdir�joinr �request�urlretrieve� SOURCE_URL�stat�print�st_size)�filename�work_directory�filepath�_Zstatinfo� r �&/home/jovyan/work/Resnet/input_data.py�maybe_download s r c C s* t jt j�jd�}t j| jd�|d�d S )N�>� )�dtyper )�numpyr �uint32�newbyteorder� frombuffer�read)� bytestream�dtr r r �_read32% s r# c C s� t d| � tj| ��p}t|�}|dkr6td|| f ��t|�}t|�}t|�}|j|| | �}tj|tjd�}|j |||d�}|S Q R X dS )zDExtract the images into a 4D uint8 numpy array [index, y, x, depth].� Extractingi z/Invalid magic number %d in MNIST image file: %s)r � N) r �gzip�openr# � ValueErrorr r r �uint8�reshape)r r! �magic� num_images�rows�cols�buf�datar r r �extract_images( s r1 � c C s<