text stringlengths 1 93.6k |
|---|
# PRED_DOWNSCALE_FACTORS is the set of integer factors indicating how much to
|
# downscale the dimensions of the ground truth prediction for each scale output.
|
# Note that the data reader under default settings creates prediction maps at
|
# one-half resolution (wrt input sizes) and hence PRED_DOWNSCALE_FACTORS =
|
# (8, 4, 2, 1) translates to 1/16, 1/8, 1/4 and 1/2 prediction sizes (s={0,1,2,3}).
|
PRED_DOWNSCALE_FACTORS = (8, 4, 2, 1)
|
# Size increments for the box sizes (\gamma) as mentioned in the paper.
|
GAMMA = [1, 1, 2, 4]
|
# Number of predefined boxes per scales (n_{mathcal{B}}).
|
NUM_BOXES_PER_SCALE = 3
|
###############################################################
|
# ---- Computing predefined box sizes and global variables
|
BOX_SIZE_BINS = [1]
|
BOX_IDX = [0]
|
g_idx = 0
|
while len(BOX_SIZE_BINS) < NUM_BOXES_PER_SCALE * len(PRED_DOWNSCALE_FACTORS):
|
gamma_idx = len(BOX_SIZE_BINS) // (len(GAMMA)-1)
|
box_size = BOX_SIZE_BINS[g_idx] + GAMMA[gamma_idx]
|
box_idx = gamma_idx*(NUM_BOXES_PER_SCALE+1) + (len(BOX_SIZE_BINS) % (len(GAMMA)-1))
|
BOX_IDX.append(box_idx)
|
BOX_SIZE_BINS.append(box_size)
|
g_idx += 1
|
BOX_INDEX = dict(zip(BOX_SIZE_BINS, BOX_IDX))
|
SCALE_BINS_ON_BOX_SIZE_BINS = [NUM_BOXES_PER_SCALE * (s + 1) \
|
for s in range(len(GAMMA))]
|
BOX_SIZE_BINS_NPY = np.array(BOX_SIZE_BINS)
|
BOXES = np.reshape(BOX_SIZE_BINS_NPY, (4, 3))
|
BOXES = BOXES[::-1]
|
metrics = ['loss1', 'new_mae']
|
# Loss Weights (to be read from .npy file while training)
|
loss_weights = None
|
matplotlib.use('Agg')
|
parser = argparse.ArgumentParser(description='PyTorch LSC-CNN Training')
|
parser.add_argument('--epochs', default=200, type=int, metavar='N',
|
help='number of total epochs to run')
|
parser.add_argument('--gpu', default=1, type=int,
|
help='GPU number')
|
parser.add_argument('--start-epoch', default=0, type=int, metavar='N',
|
help='manual epoch number (useful on restarts),\
|
0-indexed - so equal to the number of epochs completed \
|
in the last save-file')
|
parser.add_argument('-b', '--batch-size', default=4, type=int, metavar='N',
|
help='mini-batch size (default: 4),only used for train')
|
parser.add_argument('--patches', default=100, type=int, metavar='N',
|
help='number of patches per image')
|
parser.add_argument('--dataset', default="parta", type=str,
|
help='dataset to train on')
|
parser.add_argument('--lr', '--learning-rate', default=1e-3, type=float,
|
metavar='LR', help='initial learning rate')
|
parser.add_argument('--momentum', default=0.9, type=float,
|
metavar='M', help='momentum')
|
parser.add_argument('--threshold', default=-1.0, type=float,
|
metavar='M', help='fixed threshold to do NMS')
|
parser.add_argument('--weight-decay', '--wd', default=1e-4, type=float, metavar='W',
|
help='weight decay (default: 1e-4)')
|
parser.add_argument('--mle', action='store_true',
|
help='calculate mle')
|
parser.add_argument('--lsccnn', action='store_true',
|
help='use the vgg_modified network')
|
parser.add_argument('--trained-model', default='', type=str, metavar='PATH', help='filename of model to load', nargs='+')
|
dataset_paths, model_save_dir, batch_size, crop_size, dataset = None, None, None, None, None
|
class networkFunctions():
|
def __init__(self):
|
self.train_funcs = []
|
self.test_funcs = None
|
self.optimizers = None
|
'''
|
Get N channel ground truth for each scale. (Here N = 4 except for WIDERFACE)
|
B1, B2, B3, Z - Bi's are Box GT and Z is the background i.e
|
if there is not GT in any of the scales.
|
Parameters
|
-----------
|
Yss (list of torch cuda tensor)
|
bool_masks (list of torch cuda tensor) - Used only while training
|
mode (string) - To specify if the fn. is called at test/train time.
|
Returns
|
-------
|
Yss_out (list of torch cuda tensor)
|
'''
|
def get_box_gt(self, Yss):
|
Yss_out = []
|
for yss in Yss: # iterate over all scales!
|
# Make empty maps of shape gt_pred_map.shape for x, y, w, h
|
w_map = np.zeros((yss.shape[0], 4) + yss.shape[2:]) # (B,4,h,w)
|
w_map[:, 3] = 1 # Making Z initialized as 1's since they are in majority!
|
Yss_out.append(w_map)
|
assert(len(Yss_out) == 4)
|
# Get largest spatial gt
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.