python_code
stringlengths
0
992k
repo_name
stringlengths
8
46
file_path
stringlengths
5
162
# -------------------------------------------------------- # DIT: SELF-SUPERVISED PRE-TRAINING FOR DOCUMENT IMAGE TRANSFORMER # Based on Beit # --------------------------------------------------------' import argparse import datetime import numpy as np import time import torch import torch.backends.cudnn as cudnn impor...
EXA-1-master
exa/models/unilm-master/dit/classification/run_class_finetuning.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # M...
EXA-1-master
exa/models/unilm-master/dit/classification/dataset_folder.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/dit/classification/utils.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/dit/classification/modeling_finetune.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/dit/classification/optim_factory.py
#!/usr/bin/env python # -------------------------------------------------------------------------------- # MPViT: Multi-Path Vision Transformer for Dense Prediction # Copyright (c) 2022 Electronics and Telecommunications Research Institute (ETRI). # All Rights Reserved. # Written by Youngwan Lee # ---------------------...
EXA-1-master
exa/models/unilm-master/dit/text_detection/train_net.py
""" Mostly copy-paste from DINO and timm library: https://github.com/facebookresearch/dino https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/vision_transformer.py """ import warnings import math import torch import torch.nn as nn import torch.utils.checkpoint as checkpoint from timm.models.laye...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/deit.py
import os import json import copy import itertools from collections import OrderedDict import detectron2.utils.comm as comm from detectron2.evaluation import COCOEvaluator from .concern.icdar2015_eval.detection.iou import DetectionIoUEvaluator class FUNSDEvaluator(COCOEvaluator): def evaluate(self, img_ids=None)...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/funsd_evaluation.py
""" Vision Transformer (ViT) in PyTorch A PyTorch implement of Vision Transformers as described in 'An Image Is Worth 16 x 16 Words: Transformers for Image Recognition at Scale' - https://arxiv.org/abs/2010.11929 The official jax code is released and available at https://github.com/google-research/vision_transformer ...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/beit.py
from detectron2.config import CfgNode as CN def add_vit_config(cfg): """ Add config for VIT. """ _C = cfg _C.MODEL.VIT = CN() # CoaT model name. _C.MODEL.VIT.NAME = "" # Output features from CoaT backbone. _C.MODEL.VIT.OUT_FEATURES = ["layer3", "layer5", "layer7", "layer11"] ...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/config.py
from detectron2.checkpoint import DetectionCheckpointer from typing import Any import torch import torch.nn as nn #from fvcore.common.checkpoint import _IncompatibleKeys, _strip_prefix_if_present, TORCH_VERSION, quantization, \ # ObserverBase, FakeQuantizeBase from fvcore.common.checkpoint import _IncompatibleKeys,...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/mycheckpointer.py
# -------------------------------------------------------------------------------- # VIT: Multi-Path Vision Transformer for Dense Prediction # Copyright (c) 2022 Electronics and Telecommunications Research Institute (ETRI). # All Rights Reserved. # Written by Youngwan Lee # This source code is licensed(Dual License(GPL...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/backbone.py
# -------------------------------------------------------------------------------- # MPViT: Multi-Path Vision Transformer for Dense Prediction # Copyright (c) 2022 Electronics and Telecommunications Research Institute (ETRI). # All Rights Reserved. # Written by Youngwan Lee # This source code is licensed(Dual License(G...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # from https://github.com/facebookresearch/detr/blob/main/d2/detr/dataset_mapper.py import copy import logging import numpy as np import torch from detectron2.data import detection_utils as utils from detectron2.data import transforms as T __al...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/dataset_mapper.py
# -*- coding: utf-8 -*- # Copyright (c) Facebook, Inc. and its affiliates. """ This file contains components with some default boilerplate logic user may need in training / testing. They will not work for everyone, but many users may find them useful. The behavior of functions/classes in this file is subject to chang...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/mytrainer.py
import importlib from collections import OrderedDict import anyconfig import munch class Config(object): def __init__(self): pass def load(self, conf): conf = anyconfig.load(conf) return munch.munchify(conf) def compile(self, conf, return_packages=False): packages = conf...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/config.py
class AverageMeter(object): """Computes and stores the average and current value""" def __init__(self): self.reset() def reset(self): self.val = 0 self.avg = 0 self.sum = 0 self.count = 0 def update(self, val, n=1): self.val = val self.sum += val...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/average_meter.py
import os import logging import functools import json import time from datetime import datetime # from tensorboardX import SummaryWriter import yaml import cv2 import numpy as np from .config import Configurable, State class Logger(Configurable): SUMMARY_DIR_NAME = 'summaries' VISUALIZE_NAME = 'visualize' ...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/log.py
from PIL import Image import cv2 import base64 import io import numpy as np def convert(data): if isinstance(data, dict): ndata = {} for key, value in data.items(): nkey = key.decode() if nkey == 'img': img = Image.open(io.BytesIO(value)) img...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/convert.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # File : __init__.py # Author : Zhaoyi Wan <wanzhaoyi@megvii.com> # Date : 21.11.2018 # Last Modified Date: 08.01.2019 # Last Modified By : Zhaoyi Wan <wanzhaoyi@megvii.com> from .log import Logger from .average_meter import AverageMe...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/__init__.py
import os class SignalMonitor(object): def __init__(self, file_path): self.file_path = file_path def get_signal(self): if self.file_path is None: return None if os.path.exists(self.file_path): with open(self.file_path) as f: data = self.file.rea...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/signal_monitor.py
import cv2 import numpy as np from scipy import interpolate def intersection(x, p1, p2): x1, y1 = p1 x2, y2 = p2 if x2 == x1: return 0 k = (x - x1) / (x2 - x1) return k * (y2 - y1) + y1 def midpoint(p1, p2, typed=float): return [typed((p1[0] + p2[0]) / 2), typed((p1[1] + p2[1]) / 2)] ...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/box2seg.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # File : visualizer.py # Author : Zhaoyi Wan <wanzhaoyi@megvii.com> # Date : 08.01.2019 # Last Modified Date: 02.12.2019 # Last Modified By : Minghui Liao import torch import numpy as np import cv2 class Visualize: @classmethod ...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/visualizer.py
#!/usr/bin/env mdl import os BASE_DIR = os.path.dirname(os.path.realpath(__file__)) import time import json import select import traceback import socket from multiprocessing import Process, Pipe import gevent from gevent.pywsgi import WSGIServer from geventwebsocket.handler import WebSocketHandler from flask import Fl...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/webcv2/server.py
#!/usr/bin/env mdl class WebCV2: def __init__(self): import cv2 self._cv2 = cv2 from .manager import global_manager as gm self._gm = gm def __getattr__(self, name): if hasattr(self._gm, name): return getattr(self._gm, name) elif hasattr(self._cv2, nam...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/webcv2/__init__.py
#!/usr/bin/env mdl import socket import base64 import cv2 import numpy as np from collections import OrderedDict from .server import get_server def jpeg_encode(img): return cv2.imencode('.png', img)[1] def get_free_port(rng, low=2000, high=10000): in_use = True while in_use: port = rng.randint(...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/webcv2/manager.py
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/icdar2015_eval/__init__.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import math from collections import namedtuple import numpy as np from shapely.geometry import Polygon class DetectionMTWI2018Evaluator(object): def __init__( self, area_recall_constraint=0.7, area_precision_constraint=0.7, ev_param_ind_center_...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/icdar2015_eval/detection/mtwi2018.py
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/icdar2015_eval/detection/__init__.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import math from collections import namedtuple import numpy as np from shapely.geometry import Polygon class DetectionICDAR2013Evaluator(object): def __init__( self, area_recall_constraint=0.8, area_precision_constraint=0.4, ev_param_ind_center...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/icdar2015_eval/detection/icdar2013.py
#!/usr/bin/env python # -*- coding: utf-8 -*- from collections import namedtuple import numpy as np from shapely.geometry import Polygon class DetectionIoUEvaluator(object): def __init__(self, iou_constraint=0.5, area_precision_constraint=0.5): self.iou_constraint = iou_constraint self.area_precis...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/icdar2015_eval/detection/iou.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import math from collections import namedtuple import numpy as np from shapely.geometry import Polygon class DetectionDetEvalEvaluator(object): def __init__( self, area_recall_constraint=0.8, area_precision_constraint=0.4, ev_param_ind_center_d...
EXA-1-master
exa/models/unilm-master/dit/text_detection/ditod/concern/icdar2015_eval/detection/deteval.py
import os from PIL import Image import xml.etree.ElementTree as ET import numpy as np import json from PIL import Image from shutil import copyfile def convert(ROOT, TRACK, SPLIT): coco_data = { "images": [], "annotations": [], "categories": [{"id": 1, "name": "table"}, ], } DATA_D...
EXA-1-master
exa/models/unilm-master/dit/object_detection/convert_to_coco_format.py
import argparse import cv2 from ditod import add_vit_config import torch from detectron2.config import get_cfg from detectron2.utils.visualizer import ColorMode, Visualizer from detectron2.data import MetadataCatalog from detectron2.engine import DefaultPredictor def main(): parser = argparse.ArgumentParser(d...
EXA-1-master
exa/models/unilm-master/dit/object_detection/inference.py
#!/usr/bin/env python # -------------------------------------------------------------------------------- # MPViT: Multi-Path Vision Transformer for Dense Prediction # Copyright (c) 2022 Electronics and Telecommunications Research Institute (ETRI). # All Rights Reserved. # Written by Youngwan Lee # ---------------------...
EXA-1-master
exa/models/unilm-master/dit/object_detection/train_net.py
import argparse import os import cv2 import tqdm def convert(fn): # given a file name, convert it into binary and store at the same position img = cv2.imread(fn) gim = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gim = cv2.adaptiveThreshold(gim, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 45, 11)...
EXA-1-master
exa/models/unilm-master/dit/object_detection/adaptive_binarize.py
""" Mostly copy-paste from DINO and timm library: https://github.com/facebookresearch/dino https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/vision_transformer.py """ import warnings import math import torch import torch.nn as nn import torch.utils.checkpoint as checkpoint from timm.models.laye...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/deit.py
import copy import itertools import os import os.path as osp import shutil from collections import OrderedDict from xml.dom.minidom import Document import detectron2.utils.comm as comm import torch from detectron2.evaluation import COCOEvaluator from detectron2.utils.file_io import PathManager from .table_evaluation....
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/icdar_evaluation.py
""" Vision Transformer (ViT) in PyTorch A PyTorch implement of Vision Transformers as described in 'An Image Is Worth 16 x 16 Words: Transformers for Image Recognition at Scale' - https://arxiv.org/abs/2010.11929 The official jax code is released and available at https://github.com/google-research/vision_transformer ...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/beit.py
from detectron2.config import CfgNode as CN def add_vit_config(cfg): """ Add config for VIT. """ _C = cfg _C.MODEL.VIT = CN() # CoaT model name. _C.MODEL.VIT.NAME = "" # Output features from CoaT backbone. _C.MODEL.VIT.OUT_FEATURES = ["layer3", "layer5", "layer7", "layer11"] ...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/config.py
from detectron2.checkpoint import DetectionCheckpointer from typing import Any import torch import torch.nn as nn from fvcore.common.checkpoint import _IncompatibleKeys, _strip_prefix_if_present, TORCH_VERSION, quantization, \ ObserverBase, FakeQuantizeBase from torch import distributed as dist from scipy import i...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/mycheckpointer.py
# -------------------------------------------------------------------------------- # VIT: Multi-Path Vision Transformer for Dense Prediction # Copyright (c) 2022 Electronics and Telecommunications Research Institute (ETRI). # All Rights Reserved. # Written by Youngwan Lee # This source code is licensed(Dual License(GPL...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/backbone.py
# -------------------------------------------------------------------------------- # MPViT: Multi-Path Vision Transformer for Dense Prediction # Copyright (c) 2022 Electronics and Telecommunications Research Institute (ETRI). # All Rights Reserved. # Written by Youngwan Lee # This source code is licensed(Dual License(G...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # from https://github.com/facebookresearch/detr/blob/main/d2/detr/dataset_mapper.py import copy import logging import numpy as np import torch from detectron2.data import detection_utils as utils from detectron2.data import transforms as T __al...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/dataset_mapper.py
# -*- coding: utf-8 -*- # Copyright (c) Facebook, Inc. and its affiliates. """ This file contains components with some default boilerplate logic user may need in training / testing. They will not work for everyone, but many users may find them useful. The behavior of functions/classes in this file is subject to chang...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/mytrainer.py
from .evaluate import calc_table_score
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/table_evaluation/__init__.py
""" Evaluation of -.tar.gz file. Yu Fang - March 2019 """ import os import xml.dom.minidom # from eval import eval reg_gt_path = os.path.abspath("data/test") reg_gt_path_archival = os.path.abspath("data/test") reg_gt_path_modern = os.path.abspath("data/test") str_gt_path_1 = os.path.abspath("data/test") str_gt_path_...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/table_evaluation/evaluate.py
""" Data structures used by the evaluation process. Yu Fang - March 2019 """ from collections import Iterable import numpy as np from shapely.geometry import Polygon # helper functions def flatten(lis): for item in lis: if isinstance(item, Iterable) and not isinstance(item, str): for x in fl...
EXA-1-master
exa/models/unilm-master/dit/object_detection/ditod/table_evaluation/data_structure.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/engine_for_finetuning.py
""" Originally inspired by impl at https://github.com/zhunzhong07/Random-Erasing, Apache 2.0 Copyright Zhun Zhong & Liang Zheng Hacked together by / Copyright 2020 Ross Wightman Modified by Hangbo Bao, for generating the masked position for visual image transformer """ # ----------------------------------------------...
EXA-1-master
exa/models/unilm-master/beit/masking_generator.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/modeling_discrete_vae.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/transforms.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/engine_for_pretraining.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/modeling_pretrain.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/datasets.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/run_class_finetuning.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # M...
EXA-1-master
exa/models/unilm-master/beit/dataset_folder.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/run_beit_pretraining.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/utils.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/run_linear_eval.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/modeling_finetune.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/optim_factory.py
import attr import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from collections import OrderedDict from functools import partial from dall_e.utils import Conv2d @attr.s(eq=False, repr=False) class DecoderBlock(nn.Module): n_in: int = attr.ib(validator=lambda i, a, x: x >= ...
EXA-1-master
exa/models/unilm-master/beit/dall_e/decoder.py
import io, requests import torch import torch.nn as nn from dall_e.encoder import Encoder from dall_e.decoder import Decoder from dall_e.utils import map_pixels, unmap_pixels def load_model(path: str, device: torch.device = None) -> nn.Module: if path.startswith('http://') or path.startswith('https://'): ...
EXA-1-master
exa/models/unilm-master/beit/dall_e/__init__.py
import attr import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from collections import OrderedDict from functools import partial from dall_e.utils import Conv2d @attr.s(eq=False, repr=False) class EncoderBlock(nn.Module): n_in: int = attr.ib(validator=lambda i, a, x: x >= ...
EXA-1-master
exa/models/unilm-master/beit/dall_e/encoder.py
import attr import math import torch import torch.nn as nn import torch.nn.functional as F logit_laplace_eps: float = 0.1 @attr.s(eq=False) class Conv2d(nn.Module): n_in: int = attr.ib(validator=lambda i, a, x: x >= 1) n_out: int = attr.ib(validator=lambda i, a, x: x >= 1) kw: int = attr.ib(validator=lambda i...
EXA-1-master
exa/models/unilm-master/beit/dall_e/utils.py
import argparse import os import mmcv import torch from mmcv.parallel import MMDataParallel, MMDistributedDataParallel from mmcv.runner import get_dist_info, init_dist, load_checkpoint from mmcv.utils import DictAction from mmseg.apis import multi_gpu_test, single_gpu_test from mmseg.datasets import build_dataloader,...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/tools/test.py
import argparse import copy import os import os.path as osp import time import mmcv import mmcv_custom import torch from mmcv.runner import init_dist from mmcv.utils import Config, DictAction, get_git_hash from mmseg import __version__ from mmseg.apis import set_random_seed from mmcv_custom import train_segmentor fro...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/tools/train.py
import json from mmcv.runner import OPTIMIZER_BUILDERS, DefaultOptimizerConstructor from mmcv.runner import get_dist_info def get_num_layer_for_vit(var_name, num_max_layer): if var_name in ("backbone.cls_token", "backbone.mask_token", "backbone.pos_embed"): return 0 elif var_name.startswith("backbone....
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/mmcv_custom/layer_decay_optimizer_constructor.py
import random import warnings import numpy as np import torch from mmcv.parallel import MMDataParallel, MMDistributedDataParallel from mmcv.runner import build_optimizer, build_runner from mmseg.core import DistEvalHook, EvalHook from mmseg.datasets import build_dataloader, build_dataset from mmseg.utils import get_r...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/mmcv_custom/train_api.py
import mmcv import numpy as np from mmseg.datasets.builder import PIPELINES @PIPELINES.register_module() class SETR_Resize(object): """Resize images & seg. This transform resizes the input image to some scale. If the input dict contains the key "scale", then the scale in the input dict is used, othe...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/mmcv_custom/resize_transform.py
# Copyright (c) Open-MMLab. All rights reserved. import io import os import os.path as osp import pkgutil import time import warnings from collections import OrderedDict from importlib import import_module from tempfile import TemporaryDirectory import torch import torchvision from torch.optim import Optimizer from to...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/mmcv_custom/checkpoint.py
# -*- coding: utf-8 -*- from .checkpoint import load_checkpoint from .layer_decay_optimizer_constructor import LayerDecayOptimizerConstructor from .resize_transform import SETR_Resize from .apex_runner.optimizer import DistOptimizerHook from .train_api import train_segmentor __all__ = ['load_checkpoint', 'LayerDecayO...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/mmcv_custom/__init__.py
# Copyright (c) Open-MMLab. All rights reserved. import os.path as osp import platform import shutil import torch from torch.optim import Optimizer import mmcv from mmcv.runner import RUNNERS, IterBasedRunner from .checkpoint import save_checkpoint try: import apex except: print('apex is not installed') @R...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/mmcv_custom/apex_runner/apex_iter_based_runner.py
# Copyright (c) Open-MMLab. All rights reserved. import os.path as osp import time from tempfile import TemporaryDirectory import torch from torch.optim import Optimizer import mmcv from mmcv.parallel import is_module_wrapper from mmcv.runner.checkpoint import weights_to_cpu, get_state_dict try: import apex exce...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/mmcv_custom/apex_runner/checkpoint.py
# Copyright (c) Open-MMLab. All rights reserved. from .checkpoint import save_checkpoint from .apex_iter_based_runner import IterBasedRunnerAmp __all__ = [ 'save_checkpoint', 'IterBasedRunnerAmp', ]
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/mmcv_custom/apex_runner/__init__.py
from mmcv.runner import OptimizerHook, HOOKS try: import apex except: print('apex is not installed') @HOOKS.register_module() class DistOptimizerHook(OptimizerHook): """Optimizer hook for distributed training.""" def __init__(self, update_interval=1, grad_clip=None, coalesce=True, bucket_size_mb=-1, ...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/mmcv_custom/apex_runner/optimizer.py
# yapf:disable log_config = dict( interval=50, hooks=[ dict(type='TextLoggerHook', by_epoch=False), # dict(type='TensorboardLoggerHook') ]) # yapf:enable dist_params = dict(backend='nccl') log_level = 'INFO' load_from = None resume_from = None workflow = [('train', 1)] cudnn_benchmark = True...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/_base_/default_runtime.py
# dataset settings dataset_type = 'ADE20KDataset' data_root = 'data/ade/ADEChallengeData2016' img_norm_cfg = dict( mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) crop_size = (640, 640) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', reduce_zero_labe...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/_base_/datasets/ade20k_640x640.py
# dataset settings dataset_type = 'ADE20KDataset' data_root = 'data/ade/ADEChallengeData2016' img_norm_cfg = dict( mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) crop_size = (512, 512) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', reduce_zero_labe...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/_base_/datasets/ade20k.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/_base_/models/upernet_beit.py
# optimizer optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) optimizer_config = dict() # learning policy lr_config = dict(policy='poly', power=0.9, min_lr=1e-4, by_epoch=False) # runtime settings runner = dict(type='IterBasedRunner', max_iters=160000) checkpoint_config = dict(by_epoch=False, int...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/_base_/schedules/schedule_160k.py
# optimizer optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) optimizer_config = dict() # learning policy lr_config = dict(policy='poly', power=0.9, min_lr=1e-4, by_epoch=False) # runtime settings runner = dict(type='IterBasedRunner', max_iters=320000) checkpoint_config = dict(by_epoch=False, int...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/_base_/schedules/schedule_320k.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/beit/upernet/upernet_beit_large_24_512_slide_160k_ade20k_pt2ft.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/beit/upernet/upernet_beit_base_12_512_slide_160k_ade20k_pt2ft.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/beit/upernet/upernet_beit_base_12_640_slide_160k_ade20k_pt2ft.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/beit/upernet/upernet_beit_base_12_512_slide_160k_ade20k_pt.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/beit/upernet/upernet_beit_large_24_640_slide_160k_ade20k_pt2ft.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/beit/upernet/upernet_beit_base_12_512_slide_160k_ade20k_ms.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/beit/upernet/upernet_beit_large_24_512_slide_160k_ade20k_ms.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/beit/upernet/upernet_beit_base_12_640_slide_160k_ade20k_ms.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/configs/beit/upernet/upernet_beit_large_24_640_slide_160k_ade20k_ms.py
# -------------------------------------------------------- # BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254) # Github source: https://github.com/microsoft/unilm/tree/master/beit # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # By Hangbo Bao # B...
EXA-1-master
exa/models/unilm-master/beit/semantic_segmentation/backbone/beit.py
""" Simple check list from AllenNLP repo: https://github.com/allenai/allennlp/blob/master/setup.py To create the package for pypi. 1. Change the version in __init__.py, setup.py as well as docs/source/conf.py. 2. Commit these changes with the message: "Release: VERSION" 3. Add a tag in git to mark the release: "git...
EXA-1-master
exa/models/unilm-master/xtune/setup.py
# coding=utf-8 # Copyright 2020 Google and DeepMind. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law o...
EXA-1-master
exa/models/unilm-master/xtune/utils_preprocess.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a cop...
EXA-1-master
exa/models/unilm-master/xtune/src/run_qa.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors, # The HuggingFace Inc. team, and The XTREME Benchmark Authors. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with th...
EXA-1-master
exa/models/unilm-master/xtune/src/run_tag.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors, # The HuggingFace Inc. team, and The XTREME Benchmark Authors. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with th...
EXA-1-master
exa/models/unilm-master/xtune/src/utils_tag.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a cop...
EXA-1-master
exa/models/unilm-master/xtune/src/run_cls.py
import argparse if __name__ == "__main__": parser = argparse.ArgumentParser() # Required parameters parser.add_argument( "--translation_path", default=None, type=str, required=True, help="", ) drop_languages = ["en", "zh-CN", "zh", "ja", "ko", "th", "my", "...
EXA-1-master
exa/models/unilm-master/xtune/src/tools/check_many2many_alignment.py