CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
y33-j3T

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: y33-j3T/Coursera-Deep-Learning
Path: blob/master/Convolutional Neural Networks/dummy/__pycache__/cifar10.cpython-35.pyc
Views: 13377


-�Y��@s�ddlZddlZddlZddlZddlmZdZdZdZ	dZ
e	e	e
ZdZdZ
d	Ze
eZd
dd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�N)�one_hot_encodedzdata/CIFAR-10/z7https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz� ��
�i'�cCstjjtd|�S)z{
    Return the full path of a data-file for the data-set.
    If filename=="" then return the directory of the files.
    zcifar-10-batches-py/)�os�path�join�	data_path)�filename�r
�/output/cifar10.py�_get_file_pathSsrcCsOt|�}td|�t|dd��}tj|dd�}WdQRX|S)zx
    Unpickle the given file and return the data.
    Note that the appropriate dir-name is prepended the filename.
    zLoading data: �mode�rb�encoding�bytesN)r�print�open�pickle�load)r�	file_path�file�datar
r
r�	_unpickle\s
rcCsStj|dt�d}|jdtttg�}|jddddg�}|S)z�
    Convert images from the CIFAR-10 format and
    return a 4-dim array with shape: [image_number, height, width, channel]
    where the pixels are floats between 0.0 and 1.0.
    �dtypeg�o@�r�r�����)�np�array�float�reshape�num_channels�img_size�	transpose)�rawZ	raw_float�imagesr
r
r�_convert_imagesosr)cCs?t|�}|d}tj|d�}t|�}||fS)z�
    Load a pickled data-file from the CIFAR-10 data-set
    and return the converted images (see above) and the class-number
    for each image.
    sdataslabels)rr r!r))rrZ
raw_images�clsr(r
r
r�
_load_data�s

r+cCstjdtdt�dS)z�
    Download and extract the CIFAR-10 data-set if it doesn't already exist
    in data_path (set this variable first to the desired path).
    �urlZdownload_dirN)�download�maybe_download_and_extract�data_urlrr
r
r
rr.�sr.cCs*tdd�d}dd�|D�}|S)z�
    Load the names for the classes in the CIFAR-10 data-set.
    Returns a list with the names. Example: names[3] is the name
    associated with class-number 3.
    rzbatches.metaslabel_namescSsg|]}|jd��qS)zutf-8)�decode)�.0�xr
r
r�
<listcomp>�s	z$load_class_names.<locals>.<listcomp>)r)r'�namesr
r
r�load_class_names�sr5cCs�tjdttttgdt�}tjdtgdt�}d}xtt�D]q}t	ddt
|d��\}}t|�}||}||||�dd�f<||||�<|}qRW||td|d	t
�fS)
z�
    Load all the training-data for the CIFAR-10 data-set.
    The data-set is split into 5 data-files which are merged here.
    Returns the images, class-numbers and one-hot encoded class-labels.
    �shaperrr�data_batch_rN�
class_numbers�num_classes)r �zeros�_num_images_trainr%r$r"�int�range�_num_files_trainr+�str�lenrr9)r(r*�begin�iZimages_batchZ	cls_batch�
num_images�endr
r
r�load_training_data�s$#

rEcCs1tdd�\}}||td|dt�fS)z�
    Load all the test-data for the CIFAR-10 data-set.
    Returns the images, class-numbers and one-hot encoded class-labels.
    r�
test_batchr8r9)r+rr9)r(r*r
r
r�load_test_data�srG)�numpyr rrr-�datasetrrr/r%r$Z
img_size_flatr9r>Z_images_per_filer;rrr)r+r.r5rErGr
r
r
r�<module>#s*
		%