Path: blob/master/Convolutional Neural Networks/dummy/__pycache__/resnets_utils.cpython-36.pyc
24238 views
3
���Y8# � @ s� d dl Z d dlZd dlZd dlZd dlZdZdd� Zdd� Z dd� Z
d dlZd dlZd dlZd dlZd d
� Zddd
�Zdd� Z
dd� Zdd� ZdS )� Nz/output/log/c
C s4 t j� }t j� }t j||�}t jj� } t jjt�r>t jj t� t jj
t� tjd|�}
t j
� ��}t jj� }t jj||d� |j|� x�tt||
��D ]�}
|j| ||g�\}}}|
|
d dko�|
dkr�|j| |g�\}}tdjt|
|
��� tdj||�� | j|tjjtd�|
d� q�W |j� W d Q R X d S )
aC
Train the network.
Args:
loss_op: Tensorflow op to run to compute loss.
train_op: Tensorflow op to run to train network.
accuracy: Tensor of current accuracy of the model.
update_op: Tensorflow op needed to update accuracy
batch_size: Batch size
�train)�sess�coord� r zFinished epoch {}.z+Current loss: {} Current train accuracy: {}Zresnet)�global_stepN)�tf�global_variables_initializer�local_variables_initializer�groupr �Saver�gfile�Exists�LOG_DIR�DeleteRecursively�MakeDirs�cifar10�get_steps_per_epoch�Session�Coordinator�start_queue_runners�run�tqdm�range�print�format�int�save�os�path�join�request_stop)�loss_op�train_op�accuracy� update_op�
num_epochs�
batch_size� global_op�local_op�init_op�saver�steps_per_epochr r �step�_�loss�acc� r0 �)/home/jovyan/work/Resnet/resnets_utils.pyr
s(
r c C s� t j� }t j� }t j||�}t jj� }t jjt�}tj d|�}t j
� ��} t jj� }
t jj| |
d� | j
|� |j| |� x tt|��D ]}| j
|g�}q�W | j
| g�}
td� tdj|
�� |
j� W dQ R X dS )z�
Test the network.
Args:
accuracy: Tensor of current accuracy of the model.
update_op: Tensorflow op needed to update accuracy
batch_size: Batch size
�test)r r z#Finished passing over the test set.zTest accuracy: {}N)r r r r
r r �latest_checkpointr r r r r r r �restorer r r r r )r# r$ r&