Пример #1
0
    for j in range(7, 0, -1):
        if i < j:
            append_img = numpy.ones(
                img_shape[0] * img_shape[1] *
                img_shape[2]).reshape(img_shape[:1] + (1, ) + img_shape[1:])
        else:
            append_img = numpy.zeros(
                img_shape[0] * img_shape[1] *
                img_shape[2]).reshape(img_shape[:1] + (1, ) + img_shape[1:])
        lossmask = numpy.hstack([lossmask, append_img])

    lossmask = numpy.broadcast_to(lossmask, (batch_size, ) +
                                  lossmask.shape).astype(numpy.float32)
    lossmask_list.append(lossmask)

model = network.CNNAE3D512()
optimizer = chainer.optimizers.Adam(alpha=0.0002, beta1=0.5)
optimizer.setup(model)

xp = cuda.cupy if gpu > -1 else numpy
if gpu > -1:
    cuda.check_cuda_available()
    cuda.get_device(gpu).use()
    model.to_gpu()

N = len(dir_path_list)
for epoch in range(maximum_epoch):
    print epoch
    loss_gen_sum = 0.
    perm = numpy.random.permutation(N)
    for i in range(N):
Пример #2
0
                    help='File path of a downexposure model.',
                    default='./models/downexposure_model.pth')
parser.add_argument('-um',
                    help='File path of a upexposure model.',
                    default='./models/upexposure_model.pth')
args = parser.parse_args()

f_path = args.i
model_path_list = [args.dm, args.um]
base_outdir_path = args.o
gpu_list = []
if args.gpu != '-1':
    for gpu_num in (args.gpu).split(','):
        gpu_list.append(int(gpu_num))

model_list = [network.CNNAE3D512().cuda(), network.CNNAE3D512().cuda()]
print "load_weight"
for i in range(2):
    state_dict = torch.load(model_path_list[i])
    new_state_dict = OrderedDict()
    for k, v in state_dict.items():
        name = k[7:]
        # print name
        new_state_dict[name] = v
    model_list[i].load_state_dict(new_state_dict)
    # model_list[i].load_state_dict(torch.load(model_path_list[i]))


def estimate_images(input_img, model):
    model.train_dropout = False
    #input image RGB to BRG
Пример #3
0
    def __init__(self):
        parser = argparse.ArgumentParser(description='')
        parser.add_argument('-i',
                            help='Directory path of training data.',
                            default='./training_samples')
        parser.add_argument('-o',
                            help='Saved path Wof an output model file.',
                            default='./models/downexposure_model/')
        parser.add_argument(
            '-l',
            help='Learning type. (0:downexposure, 1:upexposure)',
            default='0')
        parser.add_argument('-gpu', help='GPU device specifier.', default='1')
        args = parser.parse_args()

        #cuda check
        if torch.cuda.is_available():
            self.use_cuda = True
            torch.set_default_tensor_type('torch.cuda.FloatTensor')
        else:
            self.use_cuda = False
            torch.set_default_tensor_type('torch.FloatTensor')
        self.lr = 0.0002
        # self.smoothing = config.smoothing
        # self.max_resl = config.max_resl
        # self.trns_tick = config.trns_tick
        self.TICK = 1000
        self.globalIter = 0
        self.globalTick = time.clock()
        self.kimgs = 0
        self.stack = 0

        # self.renew_everything()
        # self.use_tb = config.use_tb
        # if self.use_tb:
        # 	self.tb = tensorboard.tf_recorder()

        # gpu = int(args.gpu)
        #learning_type: 0: downexposure, 1: upexposure
        self.is_upexposure_trained = int(args.l)
        #saved path of an output model file - default: models/downexposures
        self.out_path = args.o
        self.dir_path_list = glob.glob(args.i + '/*')
        # print(self.dir_path_list)
        # self.dir_path_list = self.dir_path_list[:1]
        # print(self.dir_path_list)
        batch_size = 1
        self.maximum_epoch = 200
        self.predicted_window_len = 8

        self.lossmask_list = list()
        img_shape = (3, 512, 512)
        for i in range(self.predicted_window_len):
            lossmask = np.ones(img_shape[0] * img_shape[1] *
                               img_shape[2]).reshape(img_shape[:1] + (1, ) +
                                                     img_shape[1:])
            for j in range(7, 0, -1):
                if i < j:
                    append_img = np.ones(img_shape[0] * img_shape[1] *
                                         img_shape[2]).reshape(img_shape[:1] +
                                                               (1, ) +
                                                               img_shape[1:])
                else:
                    append_img = np.zeros(img_shape[0] * img_shape[1] *
                                          img_shape[2]).reshape(img_shape[:1] +
                                                                (1, ) +
                                                                img_shape[1:])
                lossmask = np.hstack([lossmask, append_img])
            lossmask = np.broadcast_to(lossmask, (batch_size, ) +
                                       lossmask.shape).astype(np.float32)
            self.lossmask_list.append(lossmask)

        self.model = network.CNNAE3D512()
        print('network structure')
        print(self.model)
        self.mse = torch.nn.MSELoss()
        if torch.cuda.is_available():
            self.mse = self.mse.cuda()
            self.model = self.model.cuda()
            torch.cuda.manual_seed((int)(time.time()))
            gpus = []
            for i in range(2):
                gpus.append(i)
            self.model = torch.nn.DataParallel(self.model, device_ids=gpus)

        self.TARGET_WIDTH = 512
        self.TARGET_HEIGHT = 512
        self.IMG_WIDTH = 1920
        self.IMG_HEIGHT = 1080