code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def get_kinetics_frames(kinetics_anotation_file: str) -> dict: """Given the AVA-kinetics anotation file, return a lookup to map the video id and the the set of timestamps involved of this video id. Args: kinetics_anotation_file (str): Path to the AVA-like anotation file for the kinetics...
Given the AVA-kinetics anotation file, return a lookup to map the video id and the the set of timestamps involved of this video id. Args: kinetics_anotation_file (str): Path to the AVA-like anotation file for the kinetics subset. Returns: dict: the dict keys are the kinetics vid...
get_kinetics_frames
python
open-mmlab/mmaction2
tools/data/ava_kinetics/cut_kinetics.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/ava_kinetics/cut_kinetics.py
Apache-2.0
def filter_missing_videos(kinetics_list: str, frame_lookup: dict) -> dict: """Given the kinetics700 dataset list, remove the video ids from the lookup that are missing videos or frames. Args: kinetics_list (str): Path to the kinetics700 dataset list. The content of the list should be: ...
Given the kinetics700 dataset list, remove the video ids from the lookup that are missing videos or frames. Args: kinetics_list (str): Path to the kinetics700 dataset list. The content of the list should be: ``` Path_to_video1 label_1 Path_to...
filter_missing_videos
python
open-mmlab/mmaction2
tools/data/ava_kinetics/cut_kinetics.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/ava_kinetics/cut_kinetics.py
Apache-2.0
def remove_failed_video(video_path: str) -> None: """Given the path to the video, delete the video if it cannot be read or if the actual length of the video is 0.75 seconds shorter than expected.""" try: v = decord.VideoReader(video_path) fps = v.get_avg_fps() num_frames = len(v) ...
Given the path to the video, delete the video if it cannot be read or if the actual length of the video is 0.75 seconds shorter than expected.
remove_failed_video
python
open-mmlab/mmaction2
tools/data/ava_kinetics/cut_kinetics.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/ava_kinetics/cut_kinetics.py
Apache-2.0
def download(video_identifier, output_filename, num_attempts=5, url_base='https://www.youtube.com/watch?v='): """Download a video from youtube if exists and is not blocked. arguments: --------- video_identifier: str Unique YouTube video identifier (11 chara...
Download a video from youtube if exists and is not blocked. arguments: --------- video_identifier: str Unique YouTube video identifier (11 characters) output_filename: str File path where the video will be stored.
download
python
open-mmlab/mmaction2
tools/data/gym/download.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/gym/download.py
Apache-2.0
def construct_video_filename(item, trim_format, output_dir): """Given a dataset row, this function constructs the output filename for a given video.""" youtube_id, start_time, end_time = item start_time, end_time = int(start_time * 10), int(end_time * 10) basename = '%s_%s_%s.mp4' % (youtube_id, tri...
Given a dataset row, this function constructs the output filename for a given video.
construct_video_filename
python
open-mmlab/mmaction2
tools/data/hvu/download.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/hvu/download.py
Apache-2.0
def download_clip(video_identifier, output_filename, start_time, end_time, tmp_dir='/tmp/hvu/.tmp_dir', num_attempts=5, url_base='https://www.youtube.com/watch?v='): """Download a video from youtube if exists...
Download a video from youtube if exists and is not blocked. arguments: --------- video_identifier: str Unique YouTube video identifier (11 characters) output_filename: str File path where the video will be stored. start_time: float Indicates the beginning time in seconds from...
download_clip
python
open-mmlab/mmaction2
tools/data/hvu/download.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/hvu/download.py
Apache-2.0
def parse_hvu_annotations(input_csv): """Returns a parsed DataFrame. arguments: --------- input_csv: str Path to CSV file containing the following columns: 'Tags, youtube_id, time_start, time_end' returns: ------- dataset: List of tuples. Each tuple consists of (you...
Returns a parsed DataFrame. arguments: --------- input_csv: str Path to CSV file containing the following columns: 'Tags, youtube_id, time_start, time_end' returns: ------- dataset: List of tuples. Each tuple consists of (youtube_id, time_start, time_end). The type of t...
parse_hvu_annotations
python
open-mmlab/mmaction2
tools/data/hvu/download.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/hvu/download.py
Apache-2.0
def parse_directory(path, rgb_prefix='img_', flow_x_prefix='flow_x_', flow_y_prefix='flow_y_', level=1): """Parse directories holding extracted frames from standard benchmarks. Args: path (str): Directory path to parse fram...
Parse directories holding extracted frames from standard benchmarks. Args: path (str): Directory path to parse frames. rgb_prefix (str): Prefix of generated rgb frames name. default: 'img_'. flow_x_prefix (str): Prefix of generated flow x name. default: `flow_x_`. ...
parse_directory
python
open-mmlab/mmaction2
tools/data/hvu/generate_file_list.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/hvu/generate_file_list.py
Apache-2.0
def count_files(directory, prefix_list): """Count file number with a given directory and prefix. Args: directory (str): Data directory to be search. prefix_list (list): List or prefix. Returns: list (int): Number list of the file with the prefix. """...
Count file number with a given directory and prefix. Args: directory (str): Data directory to be search. prefix_list (list): List or prefix. Returns: list (int): Number list of the file with the prefix.
count_files
python
open-mmlab/mmaction2
tools/data/hvu/generate_file_list.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/hvu/generate_file_list.py
Apache-2.0
def create_video_folders(dataset, output_dir, tmp_dir): """Creates a directory for each label name in the dataset.""" if 'label-name' not in dataset.columns: this_dir = os.path.join(output_dir, 'test') if not os.path.exists(this_dir): os.makedirs(this_dir) # I should return a...
Creates a directory for each label name in the dataset.
create_video_folders
python
open-mmlab/mmaction2
tools/data/kinetics/download.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/kinetics/download.py
Apache-2.0
def construct_video_filename(row, label_to_dir, trim_format='%06d'): """Given a dataset row, this function constructs the output filename for a given video.""" basename = '%s_%s_%s.mp4' % (row['video-id'], trim_format % row['start-time'], tri...
Given a dataset row, this function constructs the output filename for a given video.
construct_video_filename
python
open-mmlab/mmaction2
tools/data/kinetics/download.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/kinetics/download.py
Apache-2.0
def download_clip(video_identifier, output_filename, start_time, end_time, tmp_dir='/tmp/kinetics/.tmp_dir', num_attempts=5, url_base='https://www.youtube.com/watch?v='): """Download a video from youtube if e...
Download a video from youtube if exists and is not blocked. arguments: --------- video_identifier: str Unique YouTube video identifier (11 characters) output_filename: str File path where the video will be stored. start_time: float Indicates the beginning time in seconds from...
download_clip
python
open-mmlab/mmaction2
tools/data/kinetics/download.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/kinetics/download.py
Apache-2.0
def parse_kinetics_annotations(input_csv, ignore_is_cc=False): """Returns a parsed DataFrame. arguments: --------- input_csv: str Path to CSV file containing the following columns: 'YouTube Identifier,Start time,End time,Class label' returns: ------- dataset: DataFrame ...
Returns a parsed DataFrame. arguments: --------- input_csv: str Path to CSV file containing the following columns: 'YouTube Identifier,Start time,End time,Class label' returns: ------- dataset: DataFrame Pandas with the following columns: 'video-id', 'start-...
parse_kinetics_annotations
python
open-mmlab/mmaction2
tools/data/kinetics/download.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/kinetics/download.py
Apache-2.0
def _compress_images(input_output_pair, size=224): """Scale and downsample an input image to a given fps and size (shorter side size). This also removes the audio from the image. """ input_image_path, output_image_path = input_output_pair try: resize_image(input_image_path, output_image...
Scale and downsample an input image to a given fps and size (shorter side size). This also removes the audio from the image.
_compress_images
python
open-mmlab/mmaction2
tools/data/msrvtt/compress.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/msrvtt/compress.py
Apache-2.0
def _compress_videos(input_output_pair, size=224, fps=3): """Scale and downsample an input video to a given fps and size (shorter side size). This also removes the audio from the video. """ input_file_path, output_file_path = input_output_pair try: command = [ 'ffmpeg', ...
Scale and downsample an input video to a given fps and size (shorter side size). This also removes the audio from the video.
_compress_videos
python
open-mmlab/mmaction2
tools/data/msrvtt/compress.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/msrvtt/compress.py
Apache-2.0
def format_det_result(): """convert test results to specified format in MultiSports competition.""" test_results = load(args.test_result) annos = load(args.anno_path) test_videos = annos['test_videos'][0] resolutions = annos['resolution'] frm_dets = [] for pred in track(test_results, descrip...
convert test results to specified format in MultiSports competition.
format_det_result
python
open-mmlab/mmaction2
tools/data/multisports/format_det_result.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/data/multisports/format_det_result.py
Apache-2.0
def mmaction2torchserve( config_file: str, checkpoint_file: str, output_folder: str, model_name: str, label_file: str, model_version: str = '1.0', force: bool = False, ): """Converts MMAction2 model (config + checkpoint) to TorchServe `.mar`. Args: config_file (str): In MMAc...
Converts MMAction2 model (config + checkpoint) to TorchServe `.mar`. Args: config_file (str): In MMAction2 config format. checkpoint_file (str): In MMAction2 checkpoint format. output_folder (str): Folder where `{model_name}.mar` will be created. The file created will be in Torc...
mmaction2torchserve
python
open-mmlab/mmaction2
tools/deployment/mmaction2torchserve.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/deployment/mmaction2torchserve.py
Apache-2.0
def load_video_infos(ann_file): """Load the video annotations. Args: ann_file (str): A json file path of the annotation file. Returns: list[dict]: A list containing annotations for videos. """ video_infos = [] anno_database = mmengine.load(ann_file) for video_name in anno_d...
Load the video annotations. Args: ann_file (str): A json file path of the annotation file. Returns: list[dict]: A list containing annotations for videos.
load_video_infos
python
open-mmlab/mmaction2
tools/misc/bsn_proposal_generation.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/misc/bsn_proposal_generation.py
Apache-2.0
def generate_proposals(ann_file, tem_results_dir, pgm_proposals_dir, pgm_proposals_thread, **kwargs): """Generate proposals using multi-process. Args: ann_file (str): A json file path of the annotation file for all videos to be processed. tem_results_dir (str)...
Generate proposals using multi-process. Args: ann_file (str): A json file path of the annotation file for all videos to be processed. tem_results_dir (str): Directory to read tem results pgm_proposals_dir (str): Directory to save generated proposals. pgm_proposals_thread...
generate_proposals
python
open-mmlab/mmaction2
tools/misc/bsn_proposal_generation.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/misc/bsn_proposal_generation.py
Apache-2.0
def generate_features(ann_file, tem_results_dir, pgm_proposals_dir, pgm_features_dir, pgm_features_thread, **kwargs): """Generate proposals features using multi-process. Args: ann_file (str): A json file path of the annotation file for all videos to be processed. ...
Generate proposals features using multi-process. Args: ann_file (str): A json file path of the annotation file for all videos to be processed. tem_results_dir (str): Directory to read tem results. pgm_proposals_dir (str): Directory to read generated proposals. pgm_featur...
generate_features
python
open-mmlab/mmaction2
tools/misc/bsn_proposal_generation.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/misc/bsn_proposal_generation.py
Apache-2.0
def flow_to_img(raw_flow, bound=20.): """Convert flow to gray image. Args: raw_flow (np.ndarray[float]): Estimated flow with the shape (w, h). bound (float): Bound for the flow-to-image normalization. Default: 20. Returns: np.ndarray[uint8]: The result list of np.ndarray[uint8], wi...
Convert flow to gray image. Args: raw_flow (np.ndarray[float]): Estimated flow with the shape (w, h). bound (float): Bound for the flow-to-image normalization. Default: 20. Returns: np.ndarray[uint8]: The result list of np.ndarray[uint8], with shape (w, h).
flow_to_img
python
open-mmlab/mmaction2
tools/misc/flow_extraction.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/misc/flow_extraction.py
Apache-2.0
def generate_flow(frames, method='tvl1'): """Estimate flow with given frames. Args: frames (list[np.ndarray[uint8]]): List of rgb frames, with shape (w, h, 3). method (str): Use which method to generate flow. Options are 'tvl1' and 'fa...
Estimate flow with given frames. Args: frames (list[np.ndarray[uint8]]): List of rgb frames, with shape (w, h, 3). method (str): Use which method to generate flow. Options are 'tvl1' and 'farneback'. Default: 'tvl1'. Returns: ...
generate_flow
python
open-mmlab/mmaction2
tools/misc/flow_extraction.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/misc/flow_extraction.py
Apache-2.0
def extract_dense_flow(path, dest, bound=20., save_rgb=False, start_idx=0, rgb_tmpl='img_{:05d}.jpg', flow_tmpl='{}_{:05d}.jpg', method='tvl1'): """Extract...
Extract dense flow given video or frames, save them as gray-scale images. Args: path (str): Location of the input video. dest (str): The directory to store the extracted flow images. bound (float): Bound for the flow-to-image normalization. Default: 20. save_rgb (bool): Save ext...
extract_dense_flow
python
open-mmlab/mmaction2
tools/misc/flow_extraction.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/misc/flow_extraction.py
Apache-2.0
def make_grid(videos, names, rescale_factor=None): """Concat list of pictures into a single big picture, align height here.""" vis = Visualizer() ori_shapes = [vid[0].shape[:2] for vid in videos] if rescale_factor is not None: videos = [[mmcv.imrescale(img, rescale_factor) for img in video] ...
Concat list of pictures into a single big picture, align height here.
make_grid
python
open-mmlab/mmaction2
tools/visualizations/browse_dataset.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/visualizations/browse_dataset.py
Apache-2.0
def build_inputs(model: nn.Module, video_path: str, use_frames: bool = False) -> Dict: """build inputs for GradCAM. Note that, building inputs for GradCAM is exactly the same as building inputs for Recognizer test stage. Codes from `inference_recognizer`. Args: ...
build inputs for GradCAM. Note that, building inputs for GradCAM is exactly the same as building inputs for Recognizer test stage. Codes from `inference_recognizer`. Args: model (nn.Module): Recognizer model. video_path (str): video file/url or rawframes directory. use_frames (bool...
build_inputs
python
open-mmlab/mmaction2
tools/visualizations/vis_cam.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/visualizations/vis_cam.py
Apache-2.0
def _resize_frames(frame_list: List[np.ndarray], scale: Optional[Tuple[int]] = None, keep_ratio: bool = True, interpolation: str = 'bilinear') -> List[np.ndarray]: """Resize frames according to given scale. Codes are modified from `mmaction/datasets/tran...
Resize frames according to given scale. Codes are modified from `mmaction/datasets/transforms/processing.py`, `Resize` class. Args: frame_list (list[np.ndarray]): Frames to be resized. scale (tuple[int]): If keep_ratio is True, it serves as scaling factor or maximum size: the i...
_resize_frames
python
open-mmlab/mmaction2
tools/visualizations/vis_cam.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/visualizations/vis_cam.py
Apache-2.0
def plot_curve(lr_list, args, param_name, iters_per_epoch, by_epoch=True): """Plot learning rate vs iter graph.""" try: import seaborn as sns sns.set_style(args.style) except ImportError: pass wind_w, wind_h = args.window_size.split('*') wind_w, wind_h = int(wind_w), int(win...
Plot learning rate vs iter graph.
plot_curve
python
open-mmlab/mmaction2
tools/visualizations/vis_scheduler.py
https://github.com/open-mmlab/mmaction2/blob/master/tools/visualizations/vis_scheduler.py
Apache-2.0