Ejemplo n.º 1
0
'''
@Author: xxxmy
@Github: github.com/VectXmy
@Date: 2019-09-26
@Email: [email protected]
'''
from model.fcos import FCOSDetector
import torch
from dataloader.VOC_dataset import VOCDataset
import math, time
from torch.utils.tensorboard import SummaryWriter

train_dataset = VOCDataset(
    "D:\\Research\\My_tamper_detect_dataset_train_val_test\\voc_dataset_tmp",
    resize_size=[512, 800],
    split='train')
val_dataset = VOCDataset(
    "D:\\Research\\My_tamper_detect_dataset_train_val_test\\voc_dataset_tmp",
    resize_size=[512, 800],
    split='val')

model = FCOSDetector(mode="training").cuda()
# model.load_state_dict(torch.load("./checkpoints/voc_512x800_loss2.0635.pth"))
optimizer = torch.optim.Adam(model.parameters(), lr=1e-4)

BATCH_SIZE = 3
EPOCHS = 25
WARMPUP_STEPS_RATIO = 0.12
# train_loader=torch.utils.data.DataLoader(train_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=train_dataset.collate_fn)
# val_loader=torch.utils.data.DataLoader(val_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=val_dataset.collate_fn)
train_loader = torch.utils.data.DataLoader(train_dataset,
Ejemplo n.º 2
0
        # compute recall and precision
        recall = tp / total_gts
        precision = tp / np.maximum(tp + fp, np.finfo(np.float64).eps)
        ap = _compute_ap(recall, precision)
        all_ap[label] = ap
        # print(recall, precision)
    return all_ap


if __name__ == "__main__":
    from model.fcos import FCOSDetector
    from demo import convertSyncBNtoBN
    from dataloader.VOC_dataset import VOCDataset

    eval_dataset = VOCDataset(cfg.dataset_dir,
                              resize_size=cfg.image_scale,
                              split='val')
    print("INFO===>eval dataset has %d imgs" % len(eval_dataset))
    eval_loader = torch.utils.data.DataLoader(
        eval_dataset,
        batch_size=1,
        shuffle=False,
        collate_fn=eval_dataset.collate_fn)
    model = FCOSDetector(mode="inference")
    model.load_state_dict(
        torch.load("voc2012_512x800_epoch61_loss0.7096.pth",
                   map_location=torch.device('cpu')))
    model = model.cuda().eval()
    print("===>success loading model")

    gt_boxes = []
Ejemplo n.º 3
0
        # compute recall and precision
        recall = tp / total_gts
        precision = tp / np.maximum(tp + fp, np.finfo(np.float64).eps)
        ap = _compute_ap(recall, precision)
        all_ap[label] = ap
        # print(recall, precision)
    return all_ap


if __name__ == "__main__":
    from model.fcos import FCOSDetector
    from demo import convertSyncBNtoBN
    from dataloader.VOC_dataset import VOCDataset

    eval_dataset = VOCDataset(
        "D:\\Research\\My_tamper_detect_dataset_train_val_test\\voc_dataset_tmp",
        resize_size=[800, 1024],
        split='test')
    print("INFO===>eval dataset has %d imgs" % len(eval_dataset))
    eval_loader = torch.utils.data.DataLoader(
        eval_dataset,
        batch_size=1,
        shuffle=False,
        collate_fn=eval_dataset.collate_fn)

    model = FCOSDetector(mode="inference")
    # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model)
    # print("INFO===>success convert BN to SyncBN")
    ## model.load_state_dict(torch.load("./logs/voc20172012_multigpu_800x1024_epoch27_loss0.5987.pth",map_location=torch.device('cpu')))
    model.load_state_dict(
        torch.load(
            "./checkPoints/checkPointsTmp/voc2012_512x800_epoch25_loss0.9422.pth",
Ejemplo n.º 4
0
'''
@Author: xxxmy
@Github: github.com/VectXmy
@Date: 2019-09-26
@Email: [email protected]
'''
from model.fcos import FCOSDetector
import torch
from dataloader.VOC_dataset import VOCDataset
import math,time
from torch.utils.tensorboard import SummaryWriter

train_dataset=VOCDataset("/home/xht/voc2012/VOCdevkit/VOC2012",resize_size=[512,800],split='train')
val_dataset=VOCDataset("/home/xht/voc2012/VOCdevkit/VOC2012",resize_size=[512,800],split='val')

model=FCOSDetector(mode="training").cuda()
model.load_state_dict(torch.load("./checkpoints/voc_512x800_loss2.0635.pth"))
optimizer=torch.optim.Adam(model.parameters(),lr=1e-4)

BATCH_SIZE=6
EPOCHS=30
WARMPUP_STEPS_RATIO=0.12
train_loader=torch.utils.data.DataLoader(train_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=train_dataset.collate_fn)
val_loader=torch.utils.data.DataLoader(val_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=val_dataset.collate_fn)
steps_per_epoch=len(train_dataset)//BATCH_SIZE
TOTAL_STEPS=steps_per_epoch*EPOCHS
WARMPUP_STEPS=TOTAL_STEPS*WARMPUP_STEPS_RATIO

GLOBAL_STEPS=1
LR_INIT=5e-5
LR_END=1e-6
Ejemplo n.º 5
0
        # compute recall and precision
        recall = tp / total_gts
        precision = tp / np.maximum(tp + fp, np.finfo(np.float64).eps)
        ap = _compute_ap(recall, precision)
        all_ap[label] = ap
        # print(recall, precision)
    return all_ap


if __name__ == "__main__":
    from model.fcos import FCOSDetector
    from demo import convertSyncBNtoBN
    from dataloader.VOC_dataset import VOCDataset

    eval_dataset = VOCDataset("/home/data/voc2007_2012/VOCdevkit/VOC2012",
                              resize_size=[800, 1024],
                              split='val2007')
    print("INFO===>eval dataset has %d imgs" % len(eval_dataset))
    eval_loader = torch.utils.data.DataLoader(
        eval_dataset,
        batch_size=1,
        shuffle=False,
        collate_fn=eval_dataset.collate_fn)

    model = FCOSDetector(mode="inference")
    # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model)
    # print("INFO===>success convert BN to SyncBN")
    model.load_state_dict(
        torch.load(
            "./logs/voc20172012_multigpu_800x1024_epoch27_loss0.5987.pth",
            map_location=torch.device('cpu')))
Ejemplo n.º 6
0
from model.fcos import FCOSDetector
import torch
from dataloader.VOC_dataset import VOCDataset
import math,time
from torch.utils.tensorboard import SummaryWriter
from model.config import DefaultConfig as cfg

train_dataset=VOCDataset(cfg.dataset_dir,resize_size=cfg.image_scale,split='train')
val_dataset=VOCDataset(cfg.dataset_dir,resize_size=[512,800],split='val')

model=FCOSDetector(mode="training").cuda()
if cfg.resume_path:
    model.load_state_dict(torch.load(cfg.resume_path))
optimizer=torch.optim.Adam(model.parameters(),lr=1e-4)

BATCH_SIZE=cfg.BATCH_SIZE
EPOCHS=cfg.EPOCHS
WARMPUP_STEPS_RATIO=cfg.WARMPUP_STEPS_RATIO

train_loader=torch.utils.data.DataLoader(train_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=train_dataset.collate_fn)
val_loader=torch.utils.data.DataLoader(val_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=val_dataset.collate_fn)
steps_per_epoch=len(train_dataset)//BATCH_SIZE
TOTAL_STEPS=steps_per_epoch*EPOCHS
WARMPUP_STEPS=TOTAL_STEPS*WARMPUP_STEPS_RATIO

GLOBAL_STEPS=cfg.GLOBAL_STEPS
LR_INIT=cfg.LR_INIT
LR_END=cfg.LR_END

writer=SummaryWriter(log_dir="./logs")