python_code
stringlengths
0
4.04M
repo_name
stringlengths
8
58
file_path
stringlengths
5
147
# Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import json,sys,os output_path = 'output/' def json_save(path, obj): with open(path, 'w') as f: json.dump(obj, f) def os_...
CoDraw-master
script/preprocess.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # Copyright 2021 Huawei Technologies Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "L...
bit-main
utils_squad.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # 2022.09.25 - Add distill_attn argument for removing attention distillation # Meta Platform...
bit-main
kd_learner_glue.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # Copyright 2021 Huawei Technologies Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "L...
bit-main
helper.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # 2022.09.25 - Add support for using quantized Bert model as teacher # Meta Platforms, Inc. ...
bit-main
quant_task_distill_squad.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # 2022.09.25 - Add default learning rate and batch size # Meta Platforms, Inc. <zechunliu@fb...
bit-main
utils_glue.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # 2022.09.25 - Add distill_attn argument for removing attention distillation # Meta Platform...
bit-main
kd_learner_squad.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # 2022.09.25 - Add support for using quantized Bert model as teacher # Meta Platforms, Inc. ...
bit-main
quant_task_distill_glue.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018,...
bit-main
transformer/configuration_utils.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018,...
bit-main
transformer/configuration_bert.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # 2022.09.25 - Add elastic quantization support # Meta Platforms, Inc. <zechunliu@fb.com> # ...
bit-main
transformer/modeling_bert_quant.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. import torch import torch.nn as nn import logging import math class LearnableBias(nn.Module): def __i...
bit-main
transformer/utils_quant.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # # Licensed under th...
bit-main
transformer/optimization.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # # Licensed under th...
bit-main
transformer/tokenization.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018,...
bit-main
transformer/modeling_bert.py
# coding=utf-8 # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. """ Utilities for working with the local dataset cache. This file is adapted from the AllenNLP library at h...
bit-main
transformer/file_utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Optional from overrides import overrides from allennlp.training.metrics.metric import Metric import torch import numpy as np from curiosity.util import get_logger log = get_logger(__name__) @Metric.register("mean_reciproc...
curiosity-main
curiosity/metrics.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. """ A database containing all the wikipedia/entity linking information. """ import random import re import subprocess import os from contextlib import contextmanager from collections import defaultdict from typing import List, Tuple, Dict, Name...
curiosity-main
curiosity/db.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. import os import numpy as np from overrides import overrides from allennlp.common.util import JsonDict from allennlp.data import Instance from allennlp.predictors.predictor import Predictor from allennlp.data.dataset_readers.dataset_reader impo...
curiosity-main
curiosity/predictors.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict, Optional, Union import math import torch from torch import nn from allennlp.nn.util import ( get_text_field_mask, sequence_cross_entropy_with_logits, masked_mean, ) from allennlp.data.vocabulary import Vocab...
curiosity-main
curiosity/models.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. """ Implement very simple similarity search """ from typing import List, Optional import pickle from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.metrics.pairwise import cosine_similarity from curiosity.db import Fact, c...
curiosity-main
curiosity/similarity.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. import logging def get_logger(name): log = logging.getLogger(name) if len(log.handlers) < 2: formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) fh = logging.Fi...
curiosity-main
curiosity/util.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict import torch from overrides import overrides from allennlp.common.registrable import Registrable from allennlp.modules.similarity_functions.similarity_function import SimilarityFunction class FactRanker(torch.nn.Module...
curiosity-main
curiosity/nn.py
curiosity-main
curiosity/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict, Optional, Union import math import torch from torch import nn from allennlp.nn.util import ( get_text_field_mask, sequence_cross_entropy_with_logits, masked_mean ) from allennlp.data.vocabulary import Vocabulary...
curiosity-main
curiosity/baseline_models.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. """ Reader for curiosity dialog dataset. Below is a sample json with relevant structure { "dialogs": [ { "messages": [ { "message": "Hi, what do you know about St. Louis' history?", ...
curiosity-main
curiosity/reader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. import os import json from itertools import cycle import click import _jsonnet from curiosity.stats import ( MajorityLikes, TfidfFactBaseline, MajorityDialogActs, MajorityPolicyActs, save_metrics, fact_length_stats, ) f...
curiosity-main
curiosity/cli.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. """ This file computes baseline accuracies based on majority based voting """ from typing import Dict, Optional, List import json import numpy as np import pandas as pd from allennlp.data.tokenizers.token import Token from curiosity.reader impo...
curiosity-main
curiosity/stats.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict, Union import torch from pytorch_pretrained_bert.modeling import BertModel from allennlp.modules.token_embedders.bert_token_embedder import PretrainedBertModel class BertEncoder(torch.nn.Module): """ Adapted ...
curiosity-main
curiosity/bert.py
#!/usr/bin/env python3 #Copyright (c) Facebook, Inc. and its affiliates. """ Reader for curiosity dialog dataset. Below is a sample json with relevant structure { "dialogs": [ { "messages": [ { "message": "Hi, what do you know about St. Louis' history?", ...
curiosity-main
curiosity/baseline_reader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict, List, Tuple, Optional import numpy from overrides import overrides import torch import torch.nn.functional as F from torch.nn.modules.linear import Linear from torch.nn.modules.rnn import LSTMCell from torch.nn import ...
curiosity-main
curiosity/paraphrase_models.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from curiosity.reader import CuriosityDialogReader, USER, ASSISTANT def test_text_to_instance(): facts_0 = [ {"fid": 1, "used": True}, {"fid": 1, "used": False}, {"fid": 1, "used": False}, ] facts_1 = [ ...
curiosity-main
curiosity/tests/test_reader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. import torch import pytest from curiosity.metrics import MeanReciprocalRank def test_mrr(): logits = torch.tensor([1, 2, 0.5, 0, 4, 3]).reshape(1, 1, -1) labels = torch.tensor([0, 1, 0, 0, 0, 1]).reshape(1, 1, -1) mask = torch.ten...
curiosity-main
curiosity/tests/test_metrics.py
curiosity-main
curiosity/tests/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import glob import os import shutil from os import path from typing import List from setuptools import find_packages, setup cwd = os.path.dirname(os.path.abspath(__file__)) version = "0.0.1" try: if not os.getenv("RELEA...
d2go-main
setup.py
# Adapted from https://github.com/facebookresearch/detectron2/ # Copyright (c) Facebook, Inc. and its affiliates. import argparse import glob import multiprocessing as mp import os import time import cv2 import tqdm from d2go.model_zoo import model_zoo from d2go.utils.demo_predictor import VisualizationDemo from detec...
d2go-main
demo/demo.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import os import tempfile import unittest import d2go.projects.detr.runner as oss_runner import d2go.runner.default_runner as default_runner from d2go.utils.testing.data_loader_helper import create_local_dataset # RUN: # b...
d2go-main
projects_oss/detr/test_detr_runner.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import io import unittest from typing import List import torch from detr.hub import detr_resnet50, detr_resnet50_panoptic from detr.models.backbone import Backbone from detr.models.matcher import HungarianMatcher from detr.mo...
d2go-main
projects_oss/detr/test_all.py
import logging import unittest import torch from d2go.config import CfgNode as CN from detectron2.checkpoint import DetectionCheckpointer from detectron2.modeling import BACKBONE_REGISTRY from detectron2.utils.file_io import PathManager from detr.backbone.deit import add_deit_backbone_config from detr.backbone.pit imp...
d2go-main
projects_oss/detr/test_deit_backbone.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import unittest import torch from d2go.runner import create_runner from detr.util.misc import nested_tensor_from_tensor_list from fvcore.nn import flop_count_table, FlopCountAnalysis class Tester(unittest.TestCase): @s...
d2go-main
projects_oss/detr/test_detr_export.py
# ------------------------------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] # -------------------------------------------------------------------------...
d2go-main
projects_oss/detr/setup.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # ------------------------------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LI...
d2go-main
projects_oss/detr/test_op.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import argparse import datetime import json import logging import os import random import time from datetime import timedelta from pathlib import Path import detr.util.misc as utils import numpy as np import torch import torch.distributed as dist i...
d2go-main
projects_oss/detr/main.py
#!/usr/bin/env python3 from d2go.config import CfgNode as CN from d2go.data.dataset_mappers.build import D2GO_DATA_MAPPER_REGISTRY from d2go.data.dataset_mappers.d2go_dataset_mapper import D2GoDatasetMapper from d2go.runner import GeneralizedRCNNRunner from detr.backbone.deit import add_deit_backbone_config from detr....
d2go-main
projects_oss/detr/detr/runner.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from . import datasets, models, util __all__ = ["models", "util", "datasets"]
d2go-main
projects_oss/detr/detr/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import torch from detr.models.backbone import Backbone, Joiner from detr.models.detr import DETR, PostProcess from detr.models.position_encoding import Pos...
d2go-main
projects_oss/detr/detr/hub.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Train and eval functions used in main.py """ import math import os import sys from typing import Iterable import detr.util.misc as utils import torch from detr.datasets.coco_eval import CocoEvaluator from detr.datasets.panoptic_eval import Pano...
d2go-main
projects_oss/detr/detr/engine.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Misc functions, including distributed helpers. Mostly copy-paste from torchvision references. """ import datetime import os import pickle import subpr...
d2go-main
projects_oss/detr/detr/util/misc.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Utilities for bounding box manipulation and GIoU. """ import torch from torchvision.ops.boxes import box_area def box_cxcywh_to_xyxy(x): x_c, y_c...
d2go-main
projects_oss/detr/detr/util/box_ops.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
d2go-main
projects_oss/detr/detr/util/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Plotting utilities to visualize training logs. """ from pathlib import Path, PurePath import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns import torch def plot_logs( logs, ...
d2go-main
projects_oss/detr/detr/util/plot_utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ COCO dataset which returns image_id for evaluation. Mostly copy-paste from https://github.com/pytorch/vision/blob/13b35ff/references/detection/coco_ut...
d2go-main
projects_oss/detr/detr/datasets/coco.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Transforms and data augmentation for both image + bbox. """ import random import PIL import torch import torchvision.transforms as T import torchvisio...
d2go-main
projects_oss/detr/detr/datasets/transforms.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import json import os import detr.util.misc as utils from detectron2.utils.file_io import PathManager try: from panopticapi.evaluation import pq_comp...
d2go-main
projects_oss/detr/detr/datasets/panoptic_eval.py
import math import os import random import sys import numpy as np import skimage.morphology as morp import torch import torch.utils.data as data import torchvision import torchvision.transforms as transform from detectron2.utils.file_io import PathManager from PIL import Image, ImageFilter, ImageOps from .coco import...
d2go-main
projects_oss/detr/detr/datasets/ade.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import torch.utils.data import torchvision from .ade import build as build_ade from .coco import build as build_coco def get_coco_api_from_dataset(datas...
d2go-main
projects_oss/detr/detr/datasets/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ COCO evaluator that works in distributed mode. Mostly copy-paste from https://github.com/pytorch/vision/blob/edfd5a7/references/detection/coco_eval.py...
d2go-main
projects_oss/detr/detr/datasets/coco_eval.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import json import os from pathlib import Path import numpy as np import torch from detectron2.utils.file_io import PathManager from detr.util.box_ops imp...
d2go-main
projects_oss/detr/detr/datasets/coco_panoptic.py
from typing import Dict import numpy as np import torch import torch.nn.functional as F from detectron2.modeling import build_backbone from detectron2.utils.registry import Registry from detr.models.backbone import Joiner from detr.models.position_encoding import PositionEmbeddingSine from detr.util.misc import Nested...
d2go-main
projects_oss/detr/detr/models/build.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ DETR model and criterion classes. """ import torch import torch.nn.functional as F from detectron2.config import configurable from detr.util import box...
d2go-main
projects_oss/detr/detr/models/detr.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Modules to compute the matching cost and solve the corresponding LSAP. """ import torch from detr.util.box_ops import box_cxcywh_to_xyxy, generalized_b...
d2go-main
projects_oss/detr/detr/models/matcher.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # ------------------------------------------------------------------------ # Modified from Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for ...
d2go-main
projects_oss/detr/detr/models/backbone.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Various positional encodings for the transformer. """ import math import torch from detr.util.misc import NestedTensor from torch import nn class Po...
d2go-main
projects_oss/detr/detr/models/position_encoding.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from .detr import build def build_model(args): return build(args)
d2go-main
projects_oss/detr/detr/models/__init__.py
import copy import torch import torch.nn.functional as F from torch import nn from ..util import box_ops from ..util.misc import ( accuracy, get_world_size, interpolate, is_dist_avail_and_initialized, nested_tensor_from_tensor_list, ) from .segmentation import dice_loss, sigmoid_focal_loss def _...
d2go-main
projects_oss/detr/detr/models/setcriterion.py
# ------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] # ------------------------------------------------------------------------ # Modified from DETR (ht...
d2go-main
projects_oss/detr/detr/models/deformable_detr.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ DETR Transformer class. Copy-paste from torch.nn.Transformer with modifications: * positional encodings are passed in MHattention * extra LN a...
d2go-main
projects_oss/detr/detr/models/transformer.py
# ------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] # ------------------------------------------------------------------------ # Modified from DETR (ht...
d2go-main
projects_oss/detr/detr/models/deformable_transformer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ This file provides the definition of the convolutional heads used to predict masks, as well as the losses """ import io from collections import default...
d2go-main
projects_oss/detr/detr/models/segmentation.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import numpy as np import torch import torch.nn.functional as F from d2go.registry.builtin import META_ARCH_REGISTRY from detectron2.modeling import detector_postprocess from detectron2.structures import BitMasks, Boxes, Image...
d2go-main
projects_oss/detr/detr/d2/detr.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # -*- coding: utf-8 -*- # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from d2go.config import CfgNode as CN def add_detr_config(cfg): """ Add config for DETR. """ cfg.MODEL.DETR = CN(...
d2go-main
projects_oss/detr/detr/d2/config.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from .config import add_detr_config from .dataset_mapper import DetrDatasetMapper from .detr import Detr __all__ = ["add_detr_config", "Detr", "DetrDatase...
d2go-main
projects_oss/detr/detr/d2/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import copy import logging import numpy as np import torch from detectron2.data import detection_utils as utils, transforms as T __all__ = ["DetrDatasetM...
d2go-main
projects_oss/detr/detr/d2/dataset_mapper.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # ------------------------------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LI...
d2go-main
projects_oss/detr/detr/functions/ms_deform_attn_func.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # ------------------------------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LI...
d2go-main
projects_oss/detr/detr/functions/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # ------------------------------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LI...
d2go-main
projects_oss/detr/detr/modules/ms_deform_attn.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # ------------------------------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LI...
d2go-main
projects_oss/detr/detr/modules/__init__.py
# code adapt from https://www.internalfb.com/intern/diffusion/FBS/browse/master/fbcode/mobile-vision/experimental/deit/models.py # Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. import json import math from functools import partial import torch import torch.nn as nn import torch.nn.functional as F f...
d2go-main
projects_oss/detr/detr/backbone/deit.py
# https://www.internalfb.com/intern/diffusion/FBS/browse/master/fbcode/mobile-vision/experimental/deit/pit_models.py # PiT # Copyright 2021-present NAVER Corp. # Apache License v2.0 import json import math from functools import partial import torch import torch.nn.functional as F from aml.multimodal_video.utils.einop...
d2go-main
projects_oss/detr/detr/backbone/pit.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import logging import os from typing import Any, Dict, List, Type, Union import mobile_cv.torch.utils_pytorch.comm as comm import pytorch_lightning as pl # type: ignore from d2go.config import CfgNode from d2go.runner.call...
d2go-main
tools/lightning_train_net.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Binary to convert pytorch detectron2go model to a predictor, which contains model(s) in deployable format (such as torchscript, caffe2, ...) """ import copy import logging import sys from dataclasses import dataclass fro...
d2go-main
tools/exporter.py
d2go-main
tools/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Tool for benchmarking data loading """ import logging import time from dataclasses import dataclass from typing import Type, Union import detectron2.utils.comm as comm import numpy as np from d2go.config import CfgNode f...
d2go-main
tools/benchmark_data.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Detection Training Script. """ import logging import sys from typing import Callable, Dict, List, Type, Union import detectron2.utils.comm as comm from d2go.config import CfgNode from d2go.distributed import distributed...
d2go-main
tools/train_net.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ Binary to evaluate predictor-based model (consist of models in deployable format such torchscript, caffe2, etc.) using Detectron2Go system (dataloading, evaluation, etc). """ import logging import sys from typing import ...
d2go-main
tools/evaluator.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from d2go.setup import setup_loggers setup_loggers(output_dir=None)
d2go-main
tests/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import unittest from mobile_cv.common.misc.test_utils import SubPackageInitFileTestMixin class TestSubPackageInitFile(SubPackageInitFileTestMixin, unittest.TestCase): def get_pacakge_name(self) -> str: return "...
d2go-main
tests/misc/test_sub_package_init_file.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import unittest from pathlib import Path from d2go.utils.validation_monitor import fetch_checkpoints_till_final from detectron2.utils.file_io import PathManager from mobile_cv.common.misc.file_utils import make_temp_directo...
d2go-main
tests/misc/test_validation_monitor.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import os import unittest import numpy as np from d2go.config import CfgNode from d2go.config.utils import flatten_config_dict from d2go.runner.lightning_task import GeneralizedRCNNTask from d2go.tools.lightning_train_net im...
d2go-main
tests/misc/test_lightning_train_net.py
d2go-main
tests/misc/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import glob import tempfile import unittest import d2go.utils.abnormal_checker as ac import torch class Model(torch.nn.Module): def forward(self, x): return {"loss": x} class TestUtilsAbnormalChecker(unittes...
d2go-main
tests/misc/test_utils_abnormal_checker.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import glob import logging import os import unittest from d2go.config import ( auto_scale_world_size, CfgNode, load_full_config_from_file, reroute_config_path, temp_new_allowed, ) from d2go.config.utils ...
d2go-main
tests/misc/test_config.py
import os import tempfile from d2go.utils.flop_calculator import dump_flops_info from d2go.utils.testing.data_loader_helper import ( create_detection_data_loader_on_toy_dataset, ) from d2go.utils.testing.rcnn_helper import RCNNBaseTestCases class TestFlopCount(RCNNBaseTestCases.TemplateTestCase): def setup_c...
d2go-main
tests/misc/test_flop_count.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import importlib import logging import pkgutil import unittest # NOTE: don't import anything related to D2/D2Go so that the test of one registry is # isolated from others logger = logging.getLogger(__name__) # copied fro...
d2go-main
tests/misc/test_registration.py
#!/usr/bin/env python3 # pyre-unsafe import os import unittest from unittest import mock import torch from d2go.runner.callbacks.quantization import ( get_default_qat_qconfig, ModelTransform, PostTrainingQuantization, QuantizationAwareTraining, rgetattr, rhasattr, rsetattr, ) from d2go.uti...
d2go-main
tests/runner/test_runner_lightning_quantization.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import os import unittest from copy import deepcopy from tempfile import TemporaryDirectory from typing import Dict import pytorch_lightning as pl # type: ignore import torch from d2go.config import CfgNode, temp_defrost f...
d2go-main
tests/runner/test_runner_lightning_task.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import copy import os import tempfile import unittest import d2go.runner.default_runner as default_runner import torch from d2go.registry.builtin import META_ARCH_REGISTRY from d2go.runner import create_runner from d2go.run...
d2go-main
tests/runner/test_runner_default_runner.py
d2go-main
tests/runner/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import os import unittest import d2go.runner.default_runner as default_runner import torch from d2go.registry.builtin import META_ARCH_REGISTRY from d2go.utils.testing.data_loader_helper import create_local_dataset from d2go...
d2go-main
tests/utils/test_gpu_memory_profiler.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import copy import json import os import unittest from typing import Dict, List, Optional, Tuple import d2go.runner.default_runner as default_runner import numpy as np import torch from d2go.registry.builtin import META_ARC...
d2go-main
tests/utils/test_visualization.py