# Path: src/deeplearning/train/utils.py
# def remove_resume_file(base_path):
#     try:
#         shutil.rmtree(os.path.join(base_path, 'resume'))
#     except OSError:
#         pass


import datetime
import json
import random
import multiprocessing
import threading
import time
import imp
import re
import os
import shutil
import math
import numpy as np
import six
import cPickle as pickle
import chainer
    import tensorflow as tf
from logging import getLogger
from PIL import Image
from six.moves import queue
from chainer import computational_graph
from chainer import cuda
from chainer import optimizers
from chainer import serializers
from .utils import remove_resume_file
    # Load pretrained model
    if pretrained_model is not None and pretrained_model.find("model") > -1:
        logger.info("load pretrained model : "
                    + os.path.join(db_model.trained_model_path, pretrained_model))
        serializers.load_hdf5(os.path.join(db_model.trained_model_path, pretrained_model), model)
        _backup_pretrained_model(db_model, pretrained_model)
        _delete_old_models(db_model, pretrained_model)

    # delete layer visualization cache
    for f in os.listdir(db_model.trained_model_path):
        if os.path.isdir(os.path.join(db_model.trained_model_path, f)):
            try:
                shutil.rmtree(os.path.join(db_model.trained_model_path, f))
            except Exception as e:
                logger.exception('Could not remove visualization cache. {0}'.format(e))
                raise e

    if db_model.gpu >= 0:
        cuda.get_device(db_model.gpu).use()
        model.to_gpu()

    optimizer = optimizers.MomentumSGD(lr=0.01, momentum=0.9)
    optimizer.setup(model)

    data_q = queue.Queue(maxsize=1)
    res_q = queue.Queue()

    db_model.is_trained = 1
    db_model.update_and_commit()


# Path: src/deeplearning/train/utils.py
# def remove_resume_file(base_path):
#     try:
#         shutil.rmtree(os.path.join(base_path, 'resume'))
#     except OSError:
#         pass


# Path: src/deeplearning/train/train_imagenet.py
import datetime
import json
import random
import multiprocessing
import threading
import time
import imp
import re
import os
import shutil
import math
import numpy as np
import six
import cPickle as pickle
import chainer
    import tensorflow as tf
from logging import getLogger
from PIL import Image
from six.moves import queue
from chainer import computational_graph
from chainer import cuda
from chainer import optimizers
from chainer import serializers
from .utils import remove_resume_file

    # Load pretrained model
    if pretrained_model is not None and pretrained_model.find("model") > -1:
        logger.info("load pretrained model : "
                    + os.path.join(db_model.trained_model_path, pretrained_model))
        serializers.load_hdf5(os.path.join(db_model.trained_model_path, pretrained_model), model)
        _backup_pretrained_model(db_model, pretrained_model)
        _delete_old_models(db_model, pretrained_model)

    # delete layer visualization cache
    for f in os.listdir(db_model.trained_model_path):
        if os.path.isdir(os.path.join(db_model.trained_model_path, f)):
            try:
                shutil.rmtree(os.path.join(db_model.trained_model_path, f))
            except Exception as e:
                logger.exception('Could not remove visualization cache. {0}'.format(e))
                raise e

    if db_model.gpu >= 0:
        cuda.get_device(db_model.gpu).use()
        model.to_gpu()

    optimizer = optimizers.MomentumSGD(lr=0.01, momentum=0.9)
    optimizer.setup(model)

    data_q = queue.Queue(maxsize=1)
    res_q = queue.Queue()

    db_model.is_trained = 1
    db_model.update_and_commit()


    remove_resume_file(db_model.trained_model_path)