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/__pycache__/cnn_utils.cpython-36.pyc
Views: 13373
3

e��Y�
�@s\ddlZddlZddlZddljZddlZddl	m
Z
dd�Zddd�Zdd	�Z
d
d�ZdS)
�N)�opscCs�tjdd�}tj|ddd��}tj|ddd��}tjdd�}tj|ddd��}tj|ddd��}tj|ddd��}|jd	|jd
f�}|jd	|jd
f�}|||||fS)Nzdatasets/train_signs.h5�r�train_set_x�train_set_yzdatasets/test_signs.h5�
test_set_x�
test_set_y�list_classes�r)�h5py�File�np�array�reshape�shape)�
train_dataset�train_set_x_orig�train_set_y_orig�test_dataset�test_set_x_orig�test_set_y_orig�classes�r�/home/jovyan/work/cnn_utils.py�load_datasetsr�@cCs6|jd}g}tjj|�ttjj|��}||dd�dd�dd�f}||dd�f}tj||�}	xptd|	�D]b}
||
||
||�dd�dd�dd�f}||
||
||�dd�f}||f}
|j	|
�qpW||dk�r2||	||�dd�dd�dd�f}||	||�dd�f}||f}
|j	|
�|S)a
    Creates a list of random minibatches from (X, Y)
    
    Arguments:
    X -- input data, of shape (input size, number of examples) (m, Hi, Wi, Ci)
    Y -- true "label" vector (containing 0 if cat, 1 if non-cat), of shape (1, number of examples) (m, n_y)
    mini_batch_size - size of the mini-batches, integer
    seed -- this is only for the purpose of grading, so that you're "random minibatches are the same as ours.
    
    Returns:
    mini_batches -- list of synchronous (mini_batch_X, mini_batch_Y)
    rN)
rr�random�seed�list�permutation�math�floor�range�append)�X�Y�mini_batch_sizer�m�mini_batchesr�
shuffled_X�
shuffled_Y�num_complete_minibatches�k�mini_batch_X�mini_batch_Y�
mini_batchrrr�random_mini_batchess$
, $
r/cCstj|�|jd�j}|S)Nr	�����)r�eyer�T)r$�Crrr�convert_to_one_hotBsr4cCs�tj|d�}tj|d�}tj|d�}tj|d�}tj|d�}tj|d�}||||||d�}tjdd	d
g�}	t|	|�}
tj|
�}tj��}|j||	|id�}
WdQRX|
S)N�W1�b1�W2�b2�W3�b3)r5r6r7r8r9r:�floati0r	)�	feed_dict)�tf�convert_to_tensor�placeholder�forward_propagation�argmax�Session�run)r#�
parametersr5r6r7r8r9r:�params�x�z3�p�sess�
predictionrrr�predictHs$


rK)rr)r�numpyrr
�matplotlib.pyplot�pyplot�plt�
tensorflowr=�tensorflow.python.frameworkrrr/r4rKrrrr�<module>s

)