# 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

    train_list = load_image_list(os.path.join(db_model.prepared_file_path, 'train.txt'))
    val_list = load_image_list(os.path.join(db_model.prepared_file_path, 'test.txt'))
    mean_image = pickle.load(open(os.path.join(db_model.prepared_file_path, 'mean.npy'), 'rb'))

    # @see http://qiita.com/progrommer/items/abd2276f314792c359da
    (model_dir, model_name) = os.path.split(db_model.network_path)
    model_name = re.sub(r"\.py$", "", model_name)
    model_module = load_module(model_dir, model_name)
    model = model_module.Network()

    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)

    resume_path = os.path.join(db_model.trained_model_path, 'resume')
    resume_json = os.path.join(resume_path, 'resume.json')

    resume_epoch = TrainingEpoch.deserialize(resume_json)

    # load resume data.
    resume_state = os.path.join(resume_path, 'resume.state')
    resume_model = os.path.join(resume_path, 'resume.model')
    logger.info("Load optimizer state from : {}"
                .format(resume_state))
    serializers.load_npz(resume_model, model)
    serializers.load_npz(resume_state, optimizer)

# 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


    train_list = load_image_list(os.path.join(db_model.prepared_file_path, 'train.txt'))
    val_list = load_image_list(os.path.join(db_model.prepared_file_path, 'test.txt'))
    mean_image = pickle.load(open(os.path.join(db_model.prepared_file_path, 'mean.npy'), 'rb'))

    # @see http://qiita.com/progrommer/items/abd2276f314792c359da
    (model_dir, model_name) = os.path.split(db_model.network_path)
    model_name = re.sub(r"\.py$", "", model_name)
    model_module = load_module(model_dir, model_name)
    model = model_module.Network()

    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)

    resume_path = os.path.join(db_model.trained_model_path, 'resume')
    resume_json = os.path.join(resume_path, 'resume.json')

    resume_epoch = TrainingEpoch.deserialize(resume_json)

    # load resume data.
    resume_state = os.path.join(resume_path, 'resume.state')
    resume_model = os.path.join(resume_path, 'resume.model')
    logger.info("Load optimizer state from : {}"
                .format(resume_state))
    serializers.load_npz(resume_model, model)
    serializers.load_npz(resume_state, optimizer)

    remove_resume_file(db_model.trained_model_path)