Learn practical skills, build real-world projects, and advance your career
import jovian
jovian.commit()
[jovian] Saving notebook..
import tensorflow as tf
import numpy as np
import datetime
import glob
import cv2

import utils.deeplabv3_ as build_model
import utils.draw_predict as dp
import utils.call_data as cd

class_num = 2
learning_rate = 0.001
total_epoch = 300
batch_size = 1
csvs = glob.glob('../dataset/Labelbox/*')

total_x = None

first = True
for csv in csvs:
    f_name = csv[20:-4]

    x_data_path = '../dataset/' + f_name + '/trn_img'
    y_data_path = '../dataset/' + f_name + '/trn_labelmask'
    train_x, train_y = cd.call_dataset(x_path=x_data_path,
                                      y_path=y_data_path)
    
    if first == True:
        total_x = train_x
        total_y = train_y
        first = False
    else:
        total_x = np.vstack([total_x, train_x])
        total_y = np.vstack([total_y, train_y])
    
print('data load complete!!')
    
test_img = total_x[0]
test_img = test_img.reshape([1, test_img.shape[0], test_img.shape[1], test_img.shape[2]])

tf.reset_default_graph()
    
X = tf.placeholder(tf.float32, shape=[None, None, None, 3])
Y = tf.placeholder(tf.int32, shape=[None, None, None])

model = build_model.deeplabv3(X, class_num, True)
predict = tf.argmax(model, 3)

cost = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits = model, labels = Y))
train_op = tf.train.AdamOptimizer(learning_rate).minimize(cost)

sess = tf.Session()
sess.run(tf.global_variables_initializer())

print('Data shape : {}'.format(total_x.shape))

for epoch in range(total_epoch):
    print('Epoch : {} ['.format(epoch + 1), end='')
    
    total_cost = 0
    avg_cost = 0
    
    for x_c in range(total_x.shape[0]):
        tr_x, tr_y = cd.data_reshape(total_x[x_c], total_y[x_c])
        
        _, c = sess.run([train_op, cost], feed_dict = {X : tr_x, Y : tr_y})
         
        total_cost += c
        if x_c % int(total_x.shape[0] / 10) == 0:
            print('=', end='')
            
    avg_cost = total_cost / total_x.shape[0]
    
    print('] cost : {0:.7}'.format(avg_cost))
    
    p = sess.run([predict], feed_dict = {X : test_img})
    segmentation = dp.draw_pixel(p[0][0], class_num)
    cv2.imwrite('./test/' + str(epoch) + '.png', segmentation)
    
saver = tf.train_Saver()
saver.save(sess, './model/total')
WARNING: Logging before flag parsing goes to stderr. W1019 15:10:55.848995 125108 deprecation_wrapper.py:119] From C:\Users\th_k9\Desktop\try_pupil_detection\tensorflow_version\utils\deeplabv3_.py:154: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead. W1019 15:10:55.857976 125108 deprecation_wrapper.py:119] From C:\Users\th_k9\Desktop\try_pupil_detection\tensorflow_version\utils\deeplabv3_.py:155: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead. W1019 15:10:55.868921 125108 deprecation.py:506] From C:\Users\th_k9\AppData\Local\Continuum\anaconda3\envs\Kimtae\lib\site-packages\tensorflow\python\ops\init_ops.py:1251: calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor
data load complete!!
W1019 15:10:55.920782 125108 deprecation_wrapper.py:119] From C:\Users\th_k9\Desktop\try_pupil_detection\tensorflow_version\utils\deeplabv3_.py:168: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead. W1019 15:10:55.941727 125108 deprecation.py:323] From C:\Users\th_k9\Desktop\try_pupil_detection\tensorflow_version\utils\deeplabv3_.py:113: batch_normalization (from tensorflow.python.layers.normalization) is deprecated and will be removed in a future version. Instructions for updating: Use keras.layers.BatchNormalization instead. In particular, `tf.control_dependencies(tf.GraphKeys.UPDATE_OPS)` should not be used (consult the `tf.keras.layers.batch_normalization` documentation). W1019 15:10:58.406757 125108 deprecation_wrapper.py:119] From C:\Users\th_k9\Desktop\try_pupil_detection\tensorflow_version\utils\deeplabv3_.py:29: The name tf.image.resize_bilinear is deprecated. Please use tf.compat.v1.image.resize_bilinear instead.
Data shape : (4956, 480, 640, 3) Epoch : 1 [===========] cost : 0.1395104 Epoch : 2 [===========] cost : 0.01141738 Epoch : 3 [===========] cost : 0.001912029 Epoch : 4 [===========] cost : 0.000842291 Epoch : 5 [===========] cost : 0.0006999336 Epoch : 6 [===========] cost : 0.0006306354 Epoch : 7 [===========] cost : 0.0006102638 Epoch : 8 [===========] cost : 0.000582106 Epoch : 9 [===========] cost : 0.0005704459 Epoch : 10 [===========] cost : 0.0005584873 Epoch : 11 [===========] cost : 0.000551593 Epoch : 12 [===========] cost : 0.0005447821 Epoch : 13 [===========] cost : 0.0005385838 Epoch : 14 [===========] cost : 0.0005342904 Epoch : 15 [===========] cost : 0.0005319647 Epoch : 16 [===========] cost : 0.0005318832 Epoch : 17 [===========] cost : 0.0005239991 Epoch : 18 [===========] cost : 0.0005206903 Epoch : 19 [===========] cost : 0.0005173317 Epoch : 20 [===========] cost : 0.0005140589 Epoch : 21 [===========] cost : 0.0005124908 Epoch : 22 [===========] cost : 0.0005091957 Epoch : 23 [===========] cost : 0.0005072264 Epoch : 24 [===========] cost : 0.0005045646 Epoch : 25 [===========] cost : 0.0005139258 Epoch : 26 [===========] cost : 0.0005026506 Epoch : 27 [===========] cost : 0.0004999505 Epoch : 28 [===========] cost : 0.0004977937 Epoch : 29 [===========] cost : 0.0004953456 Epoch : 30 [===========] cost : 0.0004931544 Epoch : 31 [===========] cost : 0.0004904196 Epoch : 32 [===========] cost : 0.0004894213 Epoch : 33 [===========] cost : 0.0004861307 Epoch : 34 [===========] cost : 0.0004853622 Epoch : 35 [===========] cost : 0.0004841891 Epoch : 36 [===========] cost : 0.0004836856 Epoch : 37 [===========] cost : 0.0004803619 Epoch : 38 [===========] cost : 0.0004771975 Epoch : 39 [===========] cost : 0.0004741786 Epoch : 40 [===========] cost : 0.0004816352 Epoch : 41 [===========] cost : 0.0004717966 Epoch : 42 [===========] cost : 0.0004702682 Epoch : 43 [===========] cost : 0.0004693394 Epoch : 44 [===========] cost : 0.0004661021 Epoch : 45 [===========] cost : 0.0004639434 Epoch : 46 [==========