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-36.pyc
Views: 13377
3

-�Y��@s�ddlZddlZddlZddlZddlmZdZdZdZ	dZ
e	e	e
ZdZdZ
d	Ze
eZddd�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
�#/home/jovyan/work/Resnet/cifar10.py�_get_file_pathSsrcCs>t|�}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: �rb)�mode�bytes)�encodingN)r�print�open�pickle�load)r�	file_path�file�datar
r
r�	_unpickle\s
rcCs:tj|td�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+cCstjttd�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.
    zbatches.meta)rslabel_namescSsg|]}|jd��qS)zutf-8)�decode)�.0�xr
r
r�
<listcomp>�sz$load_class_names.<locals>.<listcomp>)r)r'�namesr
r
r�load_class_names�sr5cCs�tjttttgtd�}tjtgtd�}d}x^tt�D]R}t	dt
|d�d�\}}t|�}||}||||�dd�f<||||�<|}q4W||t|t
d�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.
    )�shaperr�data_batch_r)rN)�
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rEcCs tdd�\}}||t|td�fS)z�
    Load all the test-data for the CIFAR-10 data-set.
    Returns the images, class-numbers and one-hot encoded class-labels.
    �
test_batch)r)r8r9)r+rr9)r(r*r
r
r�load_test_data�srG)r)�numpyr rrr-�datasetrrr/r%r$Z
img_size_flatr9r>Z_images_per_filer;rrr)r+r.r5rErGr
r
r
r�<module>#s*
		%