Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Convolutional Neural Networks/dummy/__pycache__/input_data.cpython-35.pyc
Views: 13377
�߱Yh � @ s d Z d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l Z d Z d d � Z d d � Z d d � Z d d d � Z d d d � Z Gd d � d e � Z d d e j d d � Z d S)z1Functions for downloading and reading MNIST data.� )�absolute_import)�division)�print_functionN)�urllib)�xrangez!http://yann.lecun.com/exdb/mnist/c C s� t j j | � s t j | � t j j | | � } t j j | � s� t j j t | | � \ } } t j | � } t d | | j d � | 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 �/output/input_data.py�maybe_download s r c C s; t j t j � j d � } t j | j d � d | �d S)N�>� �dtyper )�numpyr �uint32�newbyteorder� frombuffer�read)� bytestream�dtr r r �_read32% s r# c C s� t d | � t j | � �� } t | � } | d k rM t d | | f � � t | � } t | � } t | � } | j | | | � } t j | d t j �} | j | | | d � } | SWd QRXd S)zDExtract the images into a 4D uint8 numpy array [index, y, x, depth].� Extractingi z/Invalid magic number %d in MNIST image file: %sr � 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 sP | j d } t j | � | } t j | | f � } d | j | | j � <| S)z5Convert class labels from scalars to one-hot vectors.r r% )�shaper �arange�zeros�flat�ravel)�labels_dense�num_classes� num_labels�index_offset�labels_one_hotr r r �dense_to_one_hot8 s r= Fc C s� t d | � t j | � �| } t | � } | d k rM t d | | f � � t | � } | j | � } t j | d t j �} | r� t | � S| SWd QRXd S)z7Extract the labels into a 1D uint8 numpy array [index].r$ i z/Invalid magic number %d in MNIST label file: %sr N) r r&