sort glob expression for batch of 2 and give name of the first
This commit is contained in:
parent
dba966b512
commit
31172b6d58
@ -6,7 +6,7 @@ from collections import defaultdict
|
||||
|
||||
import numpy as np
|
||||
|
||||
from monstereo.utils import pixel_to_camera, get_keypoints
|
||||
from monoloco.utils import pixel_to_camera, get_keypoints
|
||||
|
||||
AVERAGE_Y = 0.48
|
||||
CLUSTERS = ['10', '20', '30', 'all']
|
||||
|
||||
@ -88,12 +88,12 @@ def factory_for_gt(im_size, focal_length=5.7, name=None, path_gt=None, verbose=T
|
||||
dic_gt = None
|
||||
if im_size[0] / im_size[1] > 2.5: # KITTI default
|
||||
kk = [[718.3351, 0., 600.3891], [0., 718.3351, 181.5122], [0., 0., 1.]] # Kitti calibration
|
||||
logger.info("Using KITTI calibration matrix...")
|
||||
else: # nuScenes camera parameters
|
||||
kk = [
|
||||
[im_size[0]*focal_length/Sx, 0., im_size[0]/2],
|
||||
[0., im_size[1]*focal_length/Sy, im_size[1]/2],
|
||||
[0., 0., 1.]]
|
||||
if verbose:
|
||||
logger.info("Using a standard calibration matrix...")
|
||||
|
||||
return kk, dic_gt
|
||||
|
||||
@ -61,9 +61,14 @@ def factory_from_args(args):
|
||||
|
||||
if args.net == 'monstereo':
|
||||
args.batch_size = 2
|
||||
args.images = sorted(args.images)
|
||||
else:
|
||||
args.batch_size = 1
|
||||
|
||||
if args.batch_size == 2 and not args.long_edge:
|
||||
args.long_edge = 1238
|
||||
LOG.info("Long-edge set to %i".format(args.long_edge))
|
||||
|
||||
# Make default pifpaf argument
|
||||
args.force_complete_pose = True
|
||||
LOG.info("Force complete pose is active")
|
||||
@ -108,14 +113,7 @@ def predict(args):
|
||||
print('batch %d: %s', batch_i, meta['file_name'])
|
||||
pred = [ann.inverse_transform(meta) for ann in pred]
|
||||
|
||||
if args.output_directory is None:
|
||||
splits = os.path.split(meta['file_name'])
|
||||
output_path = os.path.join(splits[0], 'out_' + splits[1])
|
||||
else:
|
||||
file_name = os.path.basename(meta['file_name'])
|
||||
output_path = os.path.join(args.output_directory, 'out_' + file_name)
|
||||
print('image', batch_i, meta['file_name'], output_path)
|
||||
|
||||
# Load image and collect pifpaf results
|
||||
if idx == 0:
|
||||
with open(meta_batch[0]['file_name'], 'rb') as f:
|
||||
cpu_image = PIL.Image.open(f).convert('RGB')
|
||||
@ -123,15 +121,24 @@ def predict(args):
|
||||
'pred': pred,
|
||||
'left': [ann.json_data() for ann in pred],
|
||||
'image': cpu_image}
|
||||
|
||||
# Set output image name
|
||||
if args.output_directory is None:
|
||||
splits = os.path.split(meta['file_name'])
|
||||
output_path = os.path.join(splits[0], 'out_' + splits[1])
|
||||
else:
|
||||
file_name = os.path.basename(meta['file_name'])
|
||||
output_path = os.path.join(args.output_directory, 'out_' + file_name)
|
||||
print('image', batch_i, meta['file_name'], output_path)
|
||||
|
||||
# Only for MonStereo
|
||||
else:
|
||||
pifpaf_outs['right'] = [ann.json_data() for ann in pred]
|
||||
|
||||
# 3D Predictions
|
||||
if args.net in ('monoloco_pp', 'monstereo'):
|
||||
|
||||
im_name = os.path.basename(meta['file_name'])
|
||||
im_size = (cpu_image.size[0], cpu_image.size[1]) # Original
|
||||
kk, dic_gt = factory_for_gt(im_size, focal_length=args.focal, name=im_name, path_gt=args.path_gt)
|
||||
kk, dic_gt = factory_for_gt(im_size, focal_length=args.focal, name=file_name, path_gt=args.path_gt)
|
||||
|
||||
# Preprocess pifpaf outputs and run monoloco
|
||||
boxes, keypoints = preprocess_pifpaf(pifpaf_outs['left'], im_size, enlarge_boxes=False)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user