Exemple #1
0
        use_GN_head = True
        prior = 0.01
        add_centerness = True
        cnt_on_reg = False

        # training
        strides = [8, 16, 32, 64, 128]
        limit_range = [[-1, 64], [64, 128], [128, 256], [256, 512], [512, 999999]]

        # inference
        score_threshold = 0.3
        nms_iou_threshold = 0.2
        max_detection_boxes_num = 20


    model = FCOSDetector(mode="inference", config=Config)
    model = torch.nn.DataParallel(model)
    model.load_state_dict(torch.load("./checkpoint/coco_37.2.pth", map_location=torch.device('cpu')))
    model = model.cuda().eval()
    print("===>success loading model")

    root = r"../eval_code/select1000_new/"
    names = os.listdir(root)
    for cnt, name in enumerate(names):
        img_bgr = cv2.imread(root + name)
        mask = np.load('masks/' + name.split('.')[0] + '.npy')
        mask = np.expand_dims(mask, 0).repeat(3, axis=0).astype(np.uint8)
        mask = torch.from_numpy(mask).cuda()
        img = cv2.cvtColor(img_bgr.copy(), cv2.COLOR_BGR2RGB)
        img1 = transforms.ToTensor()(img).cuda()
        img1.requires_grad = True
Exemple #2
0
        "cow",
        "diningtable",
        "dog",
        "horse",
        "motorbike",
        "person",
        "pottedplant",
        "sheep",
        "sofa",
        "train",
        "tvmonitor",
    )



model = FCOSDetector(mode="inference", config=Config)
# model = torch.nn.DataParallel(model)
ckpt = torch.load('/mnt/hdd1/benkebishe01/FCOS/fcos_fusion/voc2012_512x512_epoch71_loss0.7739.pth')
# ckpt = torch.load('/mnt/hdd1/benkebishe01/fcos_anchor/voc2012_512x512_epoch68_loss0.7201.pth')

model.load_state_dict(ckpt)
model.to(device).eval()
print('loading weights successfully...')

transform = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
])

def preprocess_img(img, img_size=416):
    # img = np.array(img)  # h w
Exemple #3
0
        transforms.ToTensor(),
        transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
    ])
    val_loader = torch.utils.data.DataLoader(Dataset(images_root,
                                                     val_path,
                                                     img_size=512,
                                                     transform=transform,
                                                     train=False),
                                             batch_size=64,
                                             shuffle=False)

    # 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')))
    model.load_state_dict(
        torch.load(
            "/mnt/hdd1/benkebishe01/FCOS/diou/60epoch/9nocnt_norm/voc_epoch51_loss0.2903.pth"
        ))
    # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/diou/new_voc3/voc_epoch80_loss0.8905.pth"))
    # model=convertSyncBNtoBN(model)
    # print("INFO===>success convert SyncBN to BN")
    # model = model.cuda().eval()
    model = model.to(device).eval()
    print("===>success loading model")

    gt_boxes = []
import cv2
from model.fcos import FCOSDetector
import torch
from torchvision import transforms
import numpy as np
from dataloader.VOC_dataset import VOCDataset
import time
import os
from model.config import DefaultConfig as cfg

if __name__ == "__main__":
    model = FCOSDetector(mode="inference", config=cfg)
    model.load_state_dict(
        torch.load("FCOSMASK_epoch61_loss1.0623.pth",
                   map_location=torch.device('cpu')))
    model = model.cuda().eval()
    print("===>success loading model")
    root = cfg.inference_dir
    names = os.listdir(root)
    for name in names:
        img_pad = cv2.imread(root + name)
        img = img_pad.copy()
        img_t = torch.from_numpy(img).float().permute(2, 0, 1)
        img1 = transforms.Normalize([102.9801, 115.9465, 122.7717],
                                    [1., 1., 1.])(img_t)
        img1 = img1.cuda()

        start_t = time.time()
        with torch.no_grad():
            out = model(img1.unsqueeze_(dim=0))
        end_t = time.time()
Exemple #5
0
np.random.seed(0)
cudnn.benchmark = False
cudnn.deterministic = True
random.seed(0)
transform = Transforms()
config = DefaultConfig
train_dataset = VOCDatasetMS(root_dir='/data/Datasets/voc/VOCdevkit/VOC2012',
                             scale_mode='multi',
                             split='trainval',
                             use_difficult=False,
                             is_train=True,
                             augment=transform,
                             mean=config.mean,
                             std=config.std)

model = FCOSDetector(mode="training").cuda()
model = torch.nn.DataParallel(model)
output_dir = 'train_multiscale'
if not os.path.exists(output_dir):
    os.mkdir(output_dir)

BATCH_SIZE = opt.batch_size
EPOCHS = opt.epochs
#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,
                                           num_workers=opt.n_cpu,
                                           worker_init_fn=np.random.seed(0))
print("total_images : {}".format(len(train_dataset)))
Exemple #6
0
            # append detection to results
            results.append(image_result)

        # append image to list of processed images
        # image_ids.append(generator.ids[index])

    if not len(results):
        return

    # write output
    json.dump(results, open('coco_bbox_results.json', 'w'), indent=4)
    # json.dump(image_ids, open('{}_processed_image_ids.json'.format(generator.set_name), 'w'), indent=4)

    # load results in COCO evaluation tool
    coco_true = generator.coco
    coco_pred = coco_true.loadRes('coco_bbox_results.json')

    # run COCO evaluation
    coco_eval = COCOeval(coco_true, coco_pred, 'bbox')
    coco_eval.params.imgIds = image_ids
    coco_eval.evaluate()
    coco_eval.accumulate()
    coco_eval.summarize()
    return coco_eval.stats

if __name__ == "__main__":
    generator=COCOGenerator("/home/data/coco2017/val2017","/home/data/coco2017/instances_val2017.json")
    model=FCOSDetector(mode="inference")
    model.load_state_dict(torch.load("./logs/1121/coco2017_multigpu_800x1024_epoch4_loss1.2863.pth",map_location=torch.device('cpu')))
    evaluate_coco(generator,model)
Exemple #7
0
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 = []
    gt_classes = []
    pred_boxes = []
    pred_classes = []
    pred_scores = []
    num = 0
    for img, boxes, classes in eval_loader:
        with torch.no_grad():
            out = model(img.cuda())
Exemple #8
0
        # training
        strides = [8, 16, 32, 64, 128]
        limit_range = [[-1, 64], [64, 128], [128, 256], [256, 512],
                       [512, 999999]]

        # inference
        score_threshold = 0.05
        nms_iou_threshold = 0.5
        max_detection_boxes_num = 500

    transform = transforms.Compose([
        transforms.ToTensor(),
        transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
    ])

    model = FCOSDetector(mode="inference", config=Config)
    # model = torch.nn.DataParallel(model)
    # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model)
    # print("INFO===>success convert BN to SyncBN")
    # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/fcos_val/voc2012_epoch80_loss1.1556.pth"))
    # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/diou/new_voc3/voc_epoch25_loss1.1657.pth"))
    model.load_state_dict(
        torch.load(
            "/mnt/hdd1/benkebishe01/dianwang/five/new1.0/voc_epoch29_loss0.3873.pth"
        ))
    # retinanet_kmean_ml/voc_epoch20_loss0.1154.pth
    # retinanet_ml_new/voc_epoch24_loss0.1074.pth
    # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/fcos_without_sample/voc2012_epoch74_loss0.9278.pth", map_location=torch.device('cpu')))
    # model=convertSyncBNtoBN(model)
    # print("INFO===>success convert SyncBN to BN")
    model = model.to(device).eval()
Exemple #9
0
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
# os.environ['CUDA_LAUNCH_BLOCKING'] = "1"
import functools
from model.fcos import FCOSDetector
import torch
# gpus = [0, 1]
# torch.device('cuda:2')

import torchvision.transforms as transforms
# from dataloader.VOC_dataset import VOCDataset
from dataloader.dataset import Dataset
import math, time
# from torch.utils.tensorboard import SummaryWriter
from tensorboardX import SummaryWriter

model = FCOSDetector(mode="training")
model = model.cuda().eval()

transform = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
])

# 2012_train 2007_val
cfg = {
    'images_root': '/home',
    'train_path': '/mnt/hdd1/benkebishe01/data/train.txt',
    'test_path': '/mnt/hdd1/benkebishe01/data/val.txt',
    'img_size': 512
}
Exemple #10
0
    #     limit_range=[[-1,64],[64,192],[128,192],[192,256],[256,999999]]
    #     #inference
    #     score_threshold=0.3
    #     nms_iou_threshold=0.5
    #     max_detection_boxes_num=150

    #     ##scene_head_para
    #     input_channel=512
    #     output_channel=512
    #     pooling_size=3
    #     output_class=10
    # from model.config import DefaultConfig

    # DefaultConfig.score_threshold=0.3

    model = FCOSDetector(mode="inference").cuda()
    model = torch.nn.DataParallel(model)
    # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model)
    # print("INFO===>success convert BN to SyncBN")
    model.load_state_dict(
        torch.load(
            "shidudi1e4Diormixupmuti_label_simgoid0.4_0.0001_50_C3_C4_C5_conc_max_pooling_192fcos_8001024_epoch60_loss0.0774.pth",
            map_location=torch.device('cuda')), False)

    # model=convertSyncBNtoBN(model)
    # print("INFO===>success convert SyncBN to BN")
    model = model.cuda().eval()
    print("===>success loading model")

    import os
    root = "./test_images/"
Exemple #11
0
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')))
    # model=convertSyncBNtoBN(model)
    # print("INFO===>success convert SyncBN to BN")
    model = model.cuda().eval()
    print("===>success loading model")

    gt_boxes = []
    gt_classes = []
    pred_boxes = []
    pred_classes = []
Exemple #12
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")
Exemple #13
0
        use_GN_head = True
        prior = 0.01
        add_centerness = True
        cnt_on_reg = False

        #training
        strides = [8, 16, 32, 64, 128]
        limit_range = [[-1, 64], [64, 128], [128, 256], [256, 512],
                       [512, 999999]]

        #inference
        score_threshold = 0.2
        nms_iou_threshold = 0.5
        max_detection_boxes_num = 150

    model = FCOSDetector(mode="inference", config=Config)
    # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model)
    # print("INFO===>success convert BN to SyncBN")
    model.load_state_dict(
        torch.load("./convert_weights/FCOS_R_50_FPN_1x_my.pth",
                   map_location=torch.device('cpu')))
    # model=convertSyncBNtoBN(model)
    # print("INFO===>success convert SyncBN to BN")
    model = model.cuda().eval()
    print("===>success loading model")

    import os
    root = "./test_images/"
    names = os.listdir(root)
    for name in names:
        img_bgr = cv2.imread(root + name)
Exemple #14
0
train_dataset = COCODataset(
    "/HDD/jaeha/dataset/COCO/2017/train2017",
    '/HDD/jaeha/dataset/COCO/2017/annotations/changed500_instances_train2017.json',
    transform=transform,
    resize_size=resize_)
val_dataset = COCOGenerator(
    "/HDD/jaeha/dataset/COCO/2017/val2017",
    '/HDD/jaeha/dataset/COCO/2017/annotations/changed500_instances_val2017.json',
    resize_size=resize_)

# changed_val_dataset=COCOGenerator("/HDD/jaeha/dataset/COCO/2017/val2017",
#                           '/HDD/jaeha/dataset/COCO/2017/annotations/changed_instances_train2014.json',resize_size=resize_)

# train_dataset=COCODataset("/HDD/jaeha/dataset/COCO/2017/val2017",
#                           '/HDD/jaeha/dataset/COCO/2017/annotations/instances_val2017.json',transform=transform,resize_size=[600,600])
model = FCOSDetector(mode="training").cuda()
print(model)

model = torch.nn.DataParallel(model)
# model.load_state_dict(torch.load("./checkpoint/model_{}.pth".format(21), map_location=torch.device('cuda:0')))

BATCH_SIZE = opt.batch_size
EPOCHS = opt.epochs
train_loader = torch.utils.data.DataLoader(train_dataset,
                                           batch_size=BATCH_SIZE,
                                           shuffle=True,
                                           collate_fn=train_dataset.collate_fn,
                                           num_workers=opt.n_cpu,
                                           worker_init_fn=np.random.seed(0))
steps_per_epoch = len(train_dataset) // BATCH_SIZE
TOTAL_STEPS = steps_per_epoch * EPOCHS
Exemple #15
0
        use_GN_head = True
        prior = 0.01
        add_centerness = True
        cnt_on_reg = False

        #training
        strides = [8, 16, 32, 64, 128]
        limit_range = [[-1, 64], [64, 128], [128, 256], [256, 512],
                       [512, 999999]]

        #inference
        score_threshold = 0.2
        nms_iou_threshold = 0.5
        max_detection_boxes_num = 150

    model = FCOSDetector(mode="inference", config=Config)
    # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model)
    # print("INFO===>success convert BN to SyncBN")
    # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/fcos/voc2012_512x800_epoch59_loss0.5531.pth",map_location=torch.device('cpu')))
    model.load_state_dict(
        torch.load(
            "/mnt/hdd1/benkebishe01/fcos/voc2012_512x800_epoch59_loss0.5531.pth"
        ))
    # model=convertSyncBNtoBN(model)
    # print("INFO===>success convert SyncBN to BN")
    model = model.cuda().eval()
    print("===>success loading model")

    import os
    root = "./test_images/"
    names = os.listdir(root)
Exemple #16
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
Exemple #17
0
parser.add_argument("--n_cpu", type=int, default=4, help="number of cpu threads to use during batch generation")
parser.add_argument("--n_gpu", type=str, default='0', help="number of cpu threads to use during batch generation")
opt = parser.parse_args()
os.environ["CUDA_VISIBLE_DEVICES"] = opt.n_gpu
torch.manual_seed(0)
torch.cuda.manual_seed(0)
torch.cuda.manual_seed_all(0)
np.random.seed(0)
cudnn.benchmark = False
cudnn.deterministic = True
random.seed(0)
transform = Transforms()
config = DefaultConfig
train_dataset = VOCDatasetMS(root_dir='/data/Datasets/voc/VOCdevkit/VOC2012', scale_mode='multi', split='trainval',use_difficult=False,is_train=True,augment=transform, mean=config.mean,std=config.std)

model = FCOSDetector(mode="training").cuda()
model = torch.nn.DataParallel(model)
output_dir = 'finetune_pruned'
if not os.path.exists(output_dir):
    os.mkdir(output_dir)

# model.load_state_dict(torch.load('/mnt/cephfs_new_wj/vc/zhangzhenghao/FCOS.Pytorch/output1/model_6.pth'))

BATCH_SIZE = opt.batch_size
EPOCHS = opt.epochs
#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,
                                           num_workers=opt.n_cpu, worker_init_fn=np.random.seed(0))
print("total_images : {}".format(len(train_dataset)))
steps_per_epoch = len(train_dataset) // BATCH_SIZE
Exemple #18
0
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument("--height", type=int, default=800, help="height of each image")
    parser.add_argument("--width", type=int, default=1333, help="width of each image")
    parser.add_argument("--checkpoint", type=str, default='', help='checkpoint model')
    parser.add_argument("--strict", type=int, default=1, help='strict mode load the model')
    
    opt = parser.parse_args()
    resize_size = [opt.height, opt.width]
    eval_dataset = VOCDataset(root_dir='./data/VOCdevkit/VOC2007', resize_size=resize_size,
                               split='test', use_difficult=False, is_train=False, augment=None)
    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 = torch.nn.DataParallel(model)
#     model_path = './checkpoint/VOC2007/model_90.pth'
    model_path = './checkpoint/VOC2007/model_8_800_1333_45.pth'
    model_path = './checkpoint/use_asff/model_8_800_1200_60.pth'
    model_path = './checkpoint/simo/model_8_800_1200_45.pth'
    model_path = './checkpoint/simo_asff/model_8_800_1200_50.pth'
    model_path = './checkpoint/effi_lite_simo/model_8_512_512_45.pth'
    model_path = './checkpoint/effi_lite_mimo/model_8_512_512_41.pth'
    model_path = './checkpoint/effi_lite_mimo/model_8_608_608_45.pth'
    model_path = './checkpoint/effi_lite_mimo/model_8_640_640_60.pth'
    model_path = './checkpoint/simo_dcn/model_8_720_1024_50.pth'
    model_path = './checkpoint/simo_fpn_dcn/model_8_720_1024_50.pth'
    model_path = './checkpoint/simo_fpn_dcn_focal/model_8_720_1024_45.pth'
        use_GN_head = True
        prior = 0.01
        add_centerness = True
        cnt_on_reg = False

        #training
        strides = [8, 16, 32, 64, 128]
        limit_range = [[-1, 64], [64, 128], [128, 256], [256, 512],
                       [512, 999999]]

        #inference
        score_threshold = 0.3
        nms_iou_threshold = 0.4
        max_detection_boxes_num = 300

    model = FCOSDetector(mode="inference", config=Config)
    # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model)
    # print("INFO===>success convert BN to SyncBN")
    model = torch.nn.DataParallel(model)
    model.load_state_dict(
        torch.load("./checkpoint/voc_78.7.pth",
                   map_location=torch.device('cpu')))
    # model=convertSyncBNtoBN(model)
    # print("INFO===>success convert SyncBN to BN")
    model = model.eval()
    print("===>success loading model")

    import os
    root = "./test_images/"
    names = os.listdir(root)
    for name in names:
Exemple #20
0
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
# os.environ['CUDA_LAUNCH_BLOCKING'] = "1"

from model.fcos import FCOSDetector
import torch

import torchvision.transforms as transforms
# from dataloader.VOC_dataset import VOCDataset
from dataloader.dataset import Dataset
import math, time
# from torch.utils.tensorboard import SummaryWriter
from tensorboardX import SummaryWriter


model = FCOSDetector(mode="training")
# model = torch.nn.DataParallel(model.cuda(), device_ids=range(torch.cuda.device_count()))
model = model.cuda()
# model=FCOSDetector(mode="training")
optimizer=torch.optim.Adam(model.parameters(), lr=1e-4, weight_decay=1e-4)

BATCH_SIZE = 16
EPOCHS = 60
WARMPUP_STEPS_RATIO = 0.12

transform = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize((0.485,0.456,0.406), (0.229,0.224,0.225))
])

# 2012_train 2007_val
Exemple #21
0
    transform = transforms.Compose([
        transforms.ToTensor(),
        transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
    ])
    val_loader = torch.utils.data.DataLoader(Dataset(images_root,
                                                     val_path,
                                                     img_size=512,
                                                     transform=transform,
                                                     train=False),
                                             batch_size=64,
                                             shuffle=False)
    draw = False
    if draw:
        writer = SummaryWriter(comment='voc_mAP')

    model = FCOSDetector(mode="inference")
    # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/80epoch/fcos_voc_3/voc_epoch80_loss0.8893.pth"))
    model = model.to(device).eval()
    print("===>success loading model")

    names = os.listdir(model_root)
    names = sorted(names, key=functools.cmp_to_key(compare))

    for name in names:
        # print(name)
        model.load_state_dict(torch.load(os.path.join(model_root + "/" +
                                                      name)))

        gt_boxes = []
        gt_classes = []
        pred_boxes = []
Exemple #22
0
    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",
            map_location=torch.device('cpu')))
    # model=convertSyncBNtoBN(model)
    # print("INFO===>success convert SyncBN to BN")
    model = model.cuda().eval()
    print("===>success loading model")

    gt_boxes = []
    gt_classes = []
    pred_boxes = []
np.random.seed(0)
cudnn.benchmark = False
cudnn.deterministic = True
random.seed(0)
transform = Transforms()
config = DefaultConfig
train_dataset = VOCDatasetMS(root_dir='/data/Datasets/voc/VOCdevkit/VOC2012',
                             scale_mode='multi',
                             split='trainval',
                             use_difficult=False,
                             is_train=True,
                             augment=transform,
                             mean=config.mean,
                             std=config.std)

model = FCOSDetector(mode="training").cuda()
model = torch.nn.DataParallel(model)
# model.load_state_dict(torch.load('/mnt/cephfs_new_wj/vc/zhangzhenghao/FCOS.Pytorch/output1/model_6.pth'))

BATCH_SIZE = opt.batch_size
EPOCHS = opt.epochs
#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,
                                           num_workers=opt.n_cpu,
                                           worker_init_fn=np.random.seed(0))
print("total_images : {}".format(len(train_dataset)))
steps_per_epoch = len(train_dataset) // BATCH_SIZE
TOTAL_STEPS = steps_per_epoch * EPOCHS
Exemple #24
0
torch.cuda.manual_seed_all(0)
np.random.seed(0)
cudnn.benchmark = False
cudnn.deterministic = True
random.seed(0)
transform = Transforms()
resize_size = [opt.height, opt.width]
interval = opt.interval
train_dataset = VOCDataset(root_dir='./data/VOCdevkit/VOC2007',
                           resize_size=resize_size,
                           split='trainval',
                           use_difficult=False,
                           is_train=True,
                           augment=transform)

model = FCOSDetector(mode="training").cuda()
model = torch.nn.DataParallel(model)

saved_path = opt.saved_path
if not os.path.exists(saved_path):
    os.makedirs(saved_path)

# model.load_state_dict(torch.load('./checkpoint/model_100.pth'))
# model.load_state_dict(torch.load('/mnt/cephfs_new_wj/vc/zhangzhenghao/FCOS.Pytorch/output1/model_6.pth'))

BATCH_SIZE = opt.batch_size
accumulate_step = opt.accumulate_step
EPOCHS = opt.epochs
#WARMPUP_STEPS_RATIO = 0.12
train_loader = torch.utils.data.DataLoader(train_dataset,
                                           batch_size=BATCH_SIZE,
Exemple #25
0
torch.cuda.manual_seed(0)
torch.cuda.manual_seed_all(0)
np.random.seed(0)
cudnn.benchmark = False
cudnn.deterministic = True
random.seed(0)
transform = Transforms()
resize_size = [400, 667]
train_dataset = COCODataset(
    imgs_path="./data/coco/coco2017/train2017",
    anno_path='./data/coco/coco2017/annotations/instances_train2017.json',
    is_train=True,
    resize_size=resize_size,
    transform=transform)

model = FCOSDetector(mode="training").cuda()
model = torch.nn.DataParallel(model)
BATCH_SIZE = opt.batch_size
EPOCHS = opt.epochs
train_loader = torch.utils.data.DataLoader(train_dataset,
                                           batch_size=BATCH_SIZE,
                                           shuffle=True,
                                           collate_fn=train_dataset.collate_fn,
                                           num_workers=opt.n_cpu,
                                           worker_init_fn=np.random.seed(0))
steps_per_epoch = len(train_dataset) // BATCH_SIZE
TOTAL_STEPS = steps_per_epoch * EPOCHS
WARMUP_STEPS = 500
WARMUP_FACTOR = 1.0 / 3.0
GLOBAL_STEPS = 0
LR_INIT = 0.01
        # print(recall, precision)
    return all_ap

if __name__=="__main__":
    from model.fcos import FCOSDetector
    #from demo import convertSyncBNtoBN
    from dataset.VOC_dataset import VOCDataset
    from model.config import DefaultConfig 

    config = DefaultConfig
    eval_dataset = VOCDataset(root_dir='/data/Datasets/voc/VOCdevkit/VOC2007', resize_size=[640, 800],
                               split='test', use_difficult=False, is_train=False, augment=None, mean=config.mean, std=config.std)
    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 = torch.nn.DataParallel(model)
    #model.load_state_dict(torch.load("./darknet19_ms_60epochs/model_59.pth",map_location=torch.device('cpu')))
    #model.load_state_dict(torch.load("./finetune_darknet_lasso0.3/model_slim_10.pth", map_location=torch.device('cpu')))
    model.load_state_dict(torch.load("./darknet19_ms_2x_lasso_v1_lambda5e_1_from_scratch/model_21.pth", map_location=torch.device('cpu')))
    # model=convertSyncBNtoBN(model)
    # print("INFO===>success convert SyncBN to BN")
    model=model.cuda().eval()
    print("===>success loading model")

    gt_boxes=[]
    gt_classes=[]
    pred_boxes=[]
    pred_classes=[]
Exemple #27
0
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,
                                           batch_size=BATCH_SIZE,
                                           shuffle=False,
                                           collate_fn=train_dataset.collate_fn)
val_loader = torch.utils.data.DataLoader(val_dataset,
                                         batch_size=BATCH_SIZE,
                                         shuffle=False,
    json.dump(results, open('coco_bbox_results.json', 'w'), indent=4)
    # json.dump(image_ids, open('{}_processed_image_ids.json'.format(generator.set_name), 'w'), indent=4)

    # load results in COCO evaluation tool
    coco_true = generator.coco
    coco_pred = coco_true.loadRes('coco_bbox_results.json')

    # run COCO evaluation
    coco_eval = COCOeval(coco_true, coco_pred, 'bbox')
    coco_eval.params.imgIds = image_ids
    coco_eval.evaluate()
    coco_eval.accumulate()
    coco_eval.summarize()

    return coco_eval.stats


if __name__ == "__main__":
    resize_ = [600, 600]
    generator = COCOGenerator(
        "/HDD/jaeha/dataset/COCO/2017/val2017",
        '/HDD/jaeha/dataset/COCO/2017/annotations/changed_instances_val2017.json',
        resize_size=resize_)
    model = FCOSDetector(mode="inference")
    model = torch.nn.DataParallel(model)
    model = model.cuda().eval()
    model.load_state_dict(torch.load("./checkpoint_dilation_300/model_48.pth",
                                     map_location=torch.device('cuda:0')),
                          strict=False)
    tmp = evaluate_coco(generator, model)