io_utils/time_utils

io_utils.h

#pragma once
#include<stdio.h>
#include<stdarg.h>

void PrintBinary(unsigned int value);

//#define PRINT_METADATA
#ifdef PRINT_METADATA
#define PRINTLNF(format,...) printf("("__FILE__":%d) %s: "format"\n",__LINE__,__FUNCTION__,##__VA_ARGS__)
#else
#define PRINTLNF(format,...)printf(format"\n",##__VA_ARGS__)
#endif

#define PRINT_CHAR(char_value) PRINTLNF(#char_value": %c",char_value)
#define PRINT_WCHAR(char_value)PRINTLNF(#char_value": %lc",char_value)
#define PRINT_INT(int_value)PRINTLNF(#int_value": %d",int_value)
#define PRINT_LONG(long_value)PRINTLNF(#long_value"%ld",long_value)
#define PRINT_LLONG(long_value)PRINTLNF(#long_value"%lld",long_value)
#define PRINT_BINARY(int_value)PrintBinary((unsigned int) int_value);
#define PRINT_HEX(int_value)PRINTLNF(#int_value": %#x",int_value)
#define PRINT_BOOL(bool_value)PRINTLNF(#bool_value": %s",bool_value?"true":"false")
#define PRINT_DOUBLE(double_value)PRINTLNF(#double_value": %g",double_value)
#define PRINT_STRING(string_value)PIRNTLNF(#string_value": %s",string_value)

#define PRINT_ARRAY(format,array,length)\
{\
    for(int array_index = 0;array_index<length;++array_index)\
    {\
        printf(format,array[array_index]);\
    }\
    printf("\n");\
}

#define PRINT_INT_ARRAY_LN(array,length)\
{\
    for(int i = 0;i<length;++i)\
    {\
        PRINTLNF(#array[i]"[%d]: %d",i,array[i]);\
    }\
}

#define PRINT_INT_ARRAY(array,length)PRINT_ARRAY("%d",array,length)
#define PRINT_CHAR_ARRAY(array,length)PRINT_ARRAY("%c",array,length)
#define PRINT_DOUBLE_ARRAY(array,length)PRINT_ARRAY("%g",array,length)

time_utils.h

#pragma once

#if defined(_WIN32)
#include<sys/timeb.h>
#if defined(__UNIX__)||defined(__APPLE__)
#include<time.h>
#endif

typedef long long long_time_t;

long_time_t TimeInMillisecond(void) {
#if defined(_WIN32)
    struct timeb time_buffer;
    ftime(&time_buffer);
    return time_buffer.time*1000LL+time_buffer.millitm;
#elif defined(__UNIX__)||defined(__APPLE__)
    struct timeval time_value;
    gettimeofday(&time_buffer,NULL);
    return time_buffer.tv_sec*1000LL+time_buffer.tv_usec/1000;
#elif defined(__STDC__)&&__STDC__VERSION__==201112L
    struct timespec timespec_value;
    timespec_get(&timespec_value,TIME_UTC);
    return timespec_value.tv_sec*1000LL+timespec_value.tv_nsec/1000;
#else
    time_t current_time = time(NULL);
    return current_time*1000LL;
#endif
}
#endif
```
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
把原始代码转换为PaddlePaddle 2.2.2 的代码如下: ```python import os import time import argparse import glob import cv2 import numpy as np from PIL import Image from skimage.measure import compare_psnr, compare_ssim from tensorboardX import SummaryWriter from models import RViDeNet from utils import * import paddle from paddle import nn from paddle.optimizer import optim paddle.set_device('gpu') parser = argparse.ArgumentParser(description='Pretrain denoising model') parser.add_argument('--gpu_id', dest='gpu_id', type=int, default=0, help='gpu id') parser.add_argument('--num_epochs', dest='num_epochs', type=int, default=33, help='num_epochs') parser.add_argument('--patch_size', dest='patch_size', type=int, default=128, help='patch_size') parser.add_argument('--batch_size', dest='batch_size', type=int, default=1, help='batch_size') args = parser.parse_args() save_dir = './pretrain_model' if not os.path.isdir(save_dir): os.makedirs(save_dir) gt_paths1 = glob.glob('./data/SRVD_data/raw_clean/MOT17-02_raw/*.tiff') gt_paths2 = glob.glob('./data/SRVD_data/raw_clean/MOT17-09_raw/*.tiff') gt_paths3 = glob.glob('./data/SRVD_data/raw_clean/MOT17-10_raw/*.tiff') gt_paths4 = glob.glob('./data/SRVD_data/raw_clean/MOT17-11_raw/*.tiff') gt_paths = gt_paths1 + gt_paths2 + gt_paths3 + gt_paths4 ps = args.patch_size # patch size for training batch_size = args.batch_size # batch size for training num_epochs = args.num_epochs train_dataset = DatasetDenoising(gt_paths, ps=ps) train_loader = paddle.io.DataLoader(train_dataset, batch_size=batch_size, shuffle=True, num_workers=4) model = RViDeNet() model.train() optimizer = optim.Adam(learning_rate=1e-4, parameters=model.parameters()) writer = SummaryWriter() for epoch in range(num_epochs): epoch_start_time = time.time() epoch_loss = 0 for i, (noisy_patches, gt_patches) in enumerate(train_loader()): noisy_patches = paddle.to_tensor(noisy_patches) gt_patches = paddle.to_tensor(gt_patches) output = model(noisy_patches) loss = nn.functional.mse_loss(output, gt_patches) optimizer.clear_grad() loss.backward() optimizer.step() epoch_loss += loss epoch_time = time.time() - epoch_start_time epoch_loss = epoch_loss / len(train_loader) print("Epoch [{}/{}] Loss: {:.5f} [{:.2f}s]".format(epoch + 1, num_epochs, epoch_loss, epoch_time)) writer.add_scalar("Loss/train", epoch_loss, epoch + 1) if (epoch + 1) % 10 == 0: model_path = os.path.join(save_dir, 'RViDeNet_epoch{}.pdparams'.format(epoch + 1)) paddle.save(model.state_dict(), model_path) print("Saving model to: {}".format(model_path)) writer.close() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃米饭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值