forked from cure-lab/MagicDrive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add fid code * add link * update readme * Update README.MD * Update README.MD * update readme
- Loading branch information
Showing
8 changed files
with
838 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# @package _global_ | ||
defaults: | ||
- _self_ # make sure override | ||
|
||
fid: | ||
resize: ${dataset.back_resize} # (h, w) | ||
padding: ${dataset.back_pad} # left, top, right and bottom | ||
raw_output: false | ||
# path relative to `${ROOT}` | ||
img_gen_dir: ??? | ||
|
||
runner: | ||
validation_index: all | ||
validation_times: 1 | ||
|
||
log_root_prefix: ../magicdrive-log/fid_gen | ||
show_box: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
device: null | ||
num_workers: null | ||
save_stats: false | ||
batch_size: 512 | ||
dims: 2048 | ||
ratio: -1 | ||
roota: ./data/nuscenes/samples | ||
rootb: ??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defaults: | ||
- config | ||
- fid: default | ||
- _self_ | ||
|
||
log_root_prefix: ../magicdrive-log/fid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import torch | ||
from accelerate import Accelerator | ||
|
||
|
||
def concat_from_everyone(accelerator: Accelerator, tmp): | ||
if not accelerator.use_distributed: | ||
return tmp | ||
output = [None for _ in range(accelerator.num_processes)] | ||
torch.distributed.all_gather_object(output, tmp) | ||
if accelerator.is_main_process: | ||
res = [] | ||
for tmpi in output: | ||
res += tmpi | ||
return res | ||
else: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import random | ||
from collections import OrderedDict | ||
from nuscenes.nuscenes import NuScenes | ||
|
||
|
||
def sample_token_from_scene(ratio_or_num, nusc=None, drop_desc=None): | ||
"""Sample keyframes from each scene according to ratio. | ||
if ratio_or_num >= 1, treated as num; | ||
if ratio_or_num < 1, treated as ratio; | ||
if ratio_or_num == 0, only pick the first frame; | ||
if ratio_or_num == -1, return None. | ||
Args: | ||
ratio (float): sample ratio to each scene. | ||
Returns: | ||
sample_flag_dict (dict): Dict[token, bool] | ||
scene_sample_flag_dict (dict): Dict[scene_name, Dict[token, bool]] | ||
""" | ||
if ratio_or_num == -1 and drop_desc is None: | ||
return None, None | ||
if nusc is None: | ||
nusc = NuScenes(version='v1.0-trainval', | ||
dataroot='./data/nuscenes', verbose=True) | ||
sample_flag_dict = {} | ||
scene_sample_flag_dict = {} | ||
for idx, scene in enumerate(nusc.scene): | ||
scene_name = scene['name'] | ||
frames_len = scene['nbr_samples'] | ||
sample_token = scene['first_sample_token'] | ||
# iteratively gather sample tokens from one scene | ||
token_in_this_scene = OrderedDict() | ||
for fi in range(frames_len): | ||
token_in_this_scene[sample_token] = False | ||
sample = nusc.get('sample', sample_token) | ||
sample_token = sample['next'] | ||
desc = scene['description'] | ||
if drop_desc is not None and drop_desc in desc.lower(): | ||
picked = [] # we pick nothing | ||
else: | ||
# pick tokens according to your ratio | ||
if ratio_or_num == 0: | ||
# if 0, only pick the first one | ||
picked = list(token_in_this_scene.keys())[0:1] | ||
else: | ||
if ratio_or_num >= 1: | ||
pick_num = int(ratio_or_num) | ||
else: | ||
pick_num = int(frames_len * ratio_or_num) | ||
picked = random.sample(token_in_this_scene.keys(), pick_num) | ||
for pick in picked: | ||
token_in_this_scene[pick] = True | ||
# now save data for output | ||
token_in_this_scene = dict(token_in_this_scene) | ||
scene_sample_flag_dict[scene_name] = token_in_this_scene | ||
sample_flag_dict.update(token_in_this_scene) | ||
return sample_flag_dict, scene_sample_flag_dict |
Oops, something went wrong.