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/week2/ResNets/__pycache__/resnets_utils.cpython-36.pyc
Views: 13381
3 z��Ys � @ sV d dl Z d dlZd dlZd dlZd dlZdd� Zd dd�Zdd� Z d d � Z dd� ZdS )� Nc C s� t jdd�} tj| d d d � �}tj| d d d � �}t jdd�}tj|d d d � �}tj|d d d � �}tj|d d d � �}|jd |jd f�}|jd |jd f�}|||||fS )Nzdatasets/train_signs.h5�rZtrain_set_xZtrain_set_yzdatasets/test_signs.h5Z test_set_xZ test_set_yZlist_classes� r )�h5py�File�np�array�reshape�shape)Z train_datasetZtrain_set_x_origZtrain_set_y_orig�test_datasetZtest_set_x_origZtest_set_y_orig�classes� r �0/home/jovyan/work/week2/ResNets/resnets_utils.py�load_dataset s r �@ c C s6 | j d }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) r N) r r �random�seed�list�permutation�math�floor�range�append)�X�YZmini_batch_sizer �mZmini_batchesr Z shuffled_XZ shuffled_YZnum_complete_minibatches�kZmini_batch_XZmini_batch_YZ mini_batchr r r �random_mini_batches s$ , $ r c C s t j|�| jd� j} | S )Nr �����)r �eyer �T)r �Cr r r �convert_to_one_hotA s r! c C s� |d }|d }|d }|d }|d }|d }t jt j|| �|�}t jj|�} t jt j|| �|�} t jj| �}t jt j||�|�}|S )a� Implements the forward propagation for the model: LINEAR -> RELU -> LINEAR -> RELU -> LINEAR -> SOFTMAX Arguments: X -- input dataset placeholder, of shape (input size, number of examples) parameters -- python dictionary containing your parameters "W1", "b1", "W2", "b2", "W3", "b3" the shapes are given in initialize_parameters Returns: Z3 -- the output of the last LINEAR unit �W1�b1�W2�b2�W3�b3)�tf�add�matmul�nn�relu) r � parametersr"