instruction
stringclasses
100 values
code
stringlengths
78
193k
response
stringlengths
259
170k
file
stringlengths
59
203
Add docstrings to existing functions
# Copyright (c) Facebook, Inc. and its affiliates. import logging import math from typing import List, Tuple, Union import torch from annotator.oneformer.detectron2.layers import batched_nms, cat, move_device_like from annotator.oneformer.detectron2.structures import Boxes, Instances logger = logging.getLogger(__name...
--- +++ @@ -1,154 +1,205 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import logging -import math -from typing import List, Tuple, Union -import torch - -from annotator.oneformer.detectron2.layers import batched_nms, cat, move_device_like -from annotator.oneformer.detectron2.structures import Boxes, Instances...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/proposal_generator/proposal_utils.py
Write docstrings for utility functions
import torch.nn as nn import torch.nn.functional as F from .activations import get_act_fn, get_act_layer, HardSwish from .config import layer_config_kwargs from .conv2d_layers import select_conv2d from .helpers import load_pretrained from .efficientnet_builder import * __all__ = ['mobilenetv3_rw', 'mobilenetv3_large_...
--- +++ @@ -1,308 +1,364 @@-import torch.nn as nn -import torch.nn.functional as F - -from .activations import get_act_fn, get_act_layer, HardSwish -from .config import layer_config_kwargs -from .conv2d_layers import select_conv2d -from .helpers import load_pretrained -from .efficientnet_builder import * - -__all__ = [...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/normalbae/models/submodules/efficientnet_repo/geffnet/mobilenetv3.py
Generate docstrings for each module
# Copyright (c) Facebook, Inc. and its affiliates. from typing import List import torch from torch import nn from torch.nn import functional as F from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.layers import Conv2d, ConvTranspose2d, cat, interpolate from annotator.one...
--- +++ @@ -1,193 +1,272 @@-# Copyright (c) Facebook, Inc. and its affiliates. -from typing import List -import torch -from torch import nn -from torch.nn import functional as F - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detectron2.layers import Conv2d, ConvTranspose2d, ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/roi_heads/keypoint_head.py
Add detailed docstrings explaining each function
# Copyright (c) Facebook, Inc. and its affiliates. import numpy as np from typing import List import fvcore.nn.weight_init as weight_init import torch from torch import nn from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.layers import Conv2d, ShapeSpec, get_norm from a...
--- +++ @@ -1,97 +1,118 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import numpy as np -from typing import List -import fvcore.nn.weight_init as weight_init -import torch -from torch import nn - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detectron2.layers import...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/roi_heads/box_head.py
Add docstrings to improve code quality
# Copyright (c) Facebook, Inc. and its affiliates. from typing import List import fvcore.nn.weight_init as weight_init import torch from torch import nn from torch.nn import functional as F from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.layers import Conv2d, ConvTran...
--- +++ @@ -1,215 +1,298 @@-# Copyright (c) Facebook, Inc. and its affiliates. -from typing import List -import fvcore.nn.weight_init as weight_init -import torch -from torch import nn -from torch.nn import functional as F - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detec...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/roi_heads/mask_head.py
Generate docstrings with parameter types
# Copyright (c) Facebook, Inc. and its affiliates. import logging from typing import Callable, Dict, List, Optional, Tuple, Union import torch from torch import nn from torch.nn import functional as F from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.data.detection_util...
--- +++ @@ -1,398 +1,569 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import logging -from typing import Callable, Dict, List, Optional, Tuple, Union -import torch -from torch import nn -from torch.nn import functional as F - -from annotator.oneformer.detectron2.config import configurable -from annotator.onef...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/roi_heads/fast_rcnn.py
Replace inline comments with docstrings
import torch.nn as nn import torch.nn.functional as F from .config import layer_config_kwargs, is_scriptable from .conv2d_layers import select_conv2d from .helpers import load_pretrained from .efficientnet_builder import * __all__ = ['GenEfficientNet', 'mnasnet_050', 'mnasnet_075', 'mnasnet_100', 'mnasnet_b1', 'mnasn...
--- +++ @@ -1,1187 +1,1450 @@-import torch.nn as nn -import torch.nn.functional as F - -from .config import layer_config_kwargs, is_scriptable -from .conv2d_layers import select_conv2d -from .helpers import load_pretrained -from .efficientnet_builder import * - -__all__ = ['GenEfficientNet', 'mnasnet_050', 'mnasnet_075...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/normalbae/models/submodules/efficientnet_repo/geffnet/gen_efficientnet.py
Add docstrings following best practices
# Copyright (c) Facebook, Inc. and its affiliates. import logging import numpy as np import torch from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.layers import ShapeSpec, batched_nms_rotated from annotator.oneformer.detectron2.structures import Instances, RotatedBoxes...
--- +++ @@ -1,201 +1,271 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import logging -import numpy as np -import torch - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detectron2.layers import ShapeSpec, batched_nms_rotated -from annotator.oneformer.detectron2.struct...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/roi_heads/rotated_fast_rcnn.py
Create docstrings for reusable components
# Copyright (c) Facebook, Inc. and its affiliates. import inspect import logging import numpy as np from typing import Dict, List, Optional, Tuple import torch from torch import nn from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.layers import ShapeSpec, nonzero_tuple ...
--- +++ @@ -1,622 +1,877 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import inspect -import logging -import numpy as np -from typing import Dict, List, Optional, Tuple -import torch -from torch import nn - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detectron2.la...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/roi_heads/roi_heads.py
Document this script properly
# Copyright (c) Facebook, Inc. and its affiliates. from typing import List import torch from torch import nn from torch.autograd.function import Function from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.layers import ShapeSpec from annotator.oneformer.detectron2.struct...
--- +++ @@ -1,245 +1,299 @@-# Copyright (c) Facebook, Inc. and its affiliates. -from typing import List -import torch -from torch import nn -from torch.autograd.function import Function - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detectron2.layers import ShapeSpec -from a...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/roi_heads/cascade_rcnn.py
Add minimal docstrings for each function
# Copyright (c) Facebook, Inc. and its affiliates. import contextlib import datetime import io import json import logging import numpy as np import os import shutil import annotator.oneformer.pycocotools.mask as mask_util from fvcore.common.timer import Timer from iopath.common.file_io import file_lock from PIL import ...
--- +++ @@ -1,437 +1,539 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import contextlib -import datetime -import io -import json -import logging -import numpy as np -import os -import shutil -import annotator.oneformer.pycocotools.mask as mask_util -from fvcore.common.timer import Timer -from iopath.common.fi...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/data/datasets/coco.py
Add docstrings including usage examples
# Copyright (c) Facebook, Inc. and its affiliates. import logging import math from bisect import bisect_right from typing import List import torch from fvcore.common.param_scheduler import ( CompositeParamScheduler, ConstantParamScheduler, LinearParamScheduler, ParamScheduler, ) try: from torch.opt...
--- +++ @@ -1,187 +1,246 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import logging -import math -from bisect import bisect_right -from typing import List -import torch -from fvcore.common.param_scheduler import ( - CompositeParamScheduler, - ConstantParamScheduler, - LinearParamScheduler, - Para...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/solver/lr_scheduler.py
Add clean documentation to messy code
# Copyright (c) Facebook, Inc. and its affiliates. import copy import json import os from annotator.oneformer.detectron2.data import DatasetCatalog, MetadataCatalog from annotator.oneformer.detectron2.utils.file_io import PathManager from .coco import load_coco_json, load_sem_seg __all__ = ["register_coco_panoptic",...
--- +++ @@ -1,156 +1,228 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import copy -import json -import os - -from annotator.oneformer.detectron2.data import DatasetCatalog, MetadataCatalog -from annotator.oneformer.detectron2.utils.file_io import PathManager - -from .coco import load_coco_json, load_sem_seg -...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/data/datasets/coco_panoptic.py
Annotate my code with docstrings
#!/usr/bin/env python3 # Copyright 2004-present Facebook. All Rights Reserved. import copy import numpy as np from typing import List import torch from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.structures import Boxes, Instances from annotator.oneformer.detectron2.st...
--- +++ @@ -1,205 +1,276 @@-#!/usr/bin/env python3 -# Copyright 2004-present Facebook. All Rights Reserved. -import copy -import numpy as np -from typing import List -import torch - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detectron2.structures import Boxes, Instances -f...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/tracking/bbox_iou_tracker.py
Add clean documentation to messy code
# Copyright (c) Facebook, Inc. and its affiliates. from __future__ import division from typing import Any, Dict, List, Optional, Tuple import torch from torch import device from torch.nn import functional as F from annotator.oneformer.detectron2.layers.wrappers import move_device_like, shapes_to_tensor class ImageLi...
--- +++ @@ -1,88 +1,129 @@-# Copyright (c) Facebook, Inc. and its affiliates. -from __future__ import division -from typing import Any, Dict, List, Optional, Tuple -import torch -from torch import device -from torch.nn import functional as F - -from annotator.oneformer.detectron2.layers.wrappers import move_device_like...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/structures/image_list.py
Add docstrings to incomplete code
# Copyright (c) Facebook, Inc. and its affiliates. import itertools import warnings from typing import Any, Dict, List, Tuple, Union import torch class Instances: def __init__(self, image_size: Tuple[int, int], **kwargs: Any): self._image_size = image_size self._fields: Dict[str, Any] = {} ...
--- +++ @@ -1,116 +1,194 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import itertools -import warnings -from typing import Any, Dict, List, Tuple, Union -import torch - - -class Instances: - - def __init__(self, image_size: Tuple[int, int], **kwargs: Any): - self._image_size = image_size - s...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/structures/instances.py
Create docstrings for all classes and functions
# Copyright (c) Facebook, Inc. and its affiliates. import copy import itertools import logging from collections import defaultdict from enum import Enum from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Type, Union import torch from fvcore.common.param_scheduler import ( CosineParamScheduler, ...
--- +++ @@ -1,254 +1,310 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import copy -import itertools -import logging -from collections import defaultdict -from enum import Enum -from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Type, Union -import torch -from fvcore.common.param_scheduler ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/solver/build.py
Add docstrings that explain logic
#!/usr/bin/env python3 # Copyright 2004-present Facebook. All Rights Reserved. from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.utils.registry import Registry from ..config.config import CfgNode as CfgNode_ from ..structures import Instances TRACKER_HEADS_REGISTRY = R...
--- +++ @@ -1,36 +1,64 @@-#!/usr/bin/env python3 -# Copyright 2004-present Facebook. All Rights Reserved. -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detectron2.utils.registry import Registry - -from ..config.config import CfgNode as CfgNode_ -from ..structures import Insta...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/tracking/base_tracker.py
Add docstrings for better understanding
# Copyright (c) Facebook, Inc. and its affiliates. import warnings from typing import List, Optional import torch from torch.nn import functional as F from annotator.oneformer.detectron2.utils.env import TORCH_VERSION def shapes_to_tensor(x: List[int], device: Optional[torch.device] = None) -> torch.Tensor: if ...
--- +++ @@ -1,121 +1,162 @@-# Copyright (c) Facebook, Inc. and its affiliates. - -import warnings -from typing import List, Optional -import torch -from torch.nn import functional as F - -from annotator.oneformer.detectron2.utils.env import TORCH_VERSION - - -def shapes_to_tensor(x: List[int], device: Optional[torch.de...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/layers/wrappers.py
Generate consistent docstrings
#!/usr/bin/env python3 # Copyright 2004-present Facebook. All Rights Reserved. import numpy as np from typing import List from annotator.oneformer.detectron2.config import CfgNode as CfgNode_ from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.structures import Instances...
--- +++ @@ -1,83 +1,129 @@-#!/usr/bin/env python3 -# Copyright 2004-present Facebook. All Rights Reserved. - -import numpy as np -from typing import List - -from annotator.oneformer.detectron2.config import CfgNode as CfgNode_ -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.det...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/tracking/vanilla_hungarian_bbox_iou_tracker.py
Document my Python code with docstrings
import logging import math import fvcore.nn.weight_init as weight_init import torch import torch.nn as nn from annotator.oneformer.detectron2.layers import CNNBlockBase, Conv2d, get_norm from annotator.oneformer.detectron2.modeling.backbone.fpn import _assert_strides_are_log2_contiguous from .backbone import Backbone...
--- +++ @@ -1,408 +1,524 @@-import logging -import math -import fvcore.nn.weight_init as weight_init -import torch -import torch.nn as nn - -from annotator.oneformer.detectron2.layers import CNNBlockBase, Conv2d, get_norm -from annotator.oneformer.detectron2.modeling.backbone.fpn import _assert_strides_are_log2_contigu...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/backbone/vit.py
Generate NumPy-style docstrings
# Copyright (c) Facebook, Inc. and its affiliates. # -*- coding: utf-8 -*- import typing from typing import Any, List import fvcore from fvcore.nn import activation_count, flop_count, parameter_count, parameter_count_table from torch import nn from annotator.oneformer.detectron2.export import TracingAdapter __all__ ...
--- +++ @@ -1,126 +1,188 @@-# Copyright (c) Facebook, Inc. and its affiliates. -# -*- coding: utf-8 -*- - -import typing -from typing import Any, List -import fvcore -from fvcore.nn import activation_count, flop_count, parameter_count, parameter_count_table -from torch import nn - -from annotator.oneformer.detectron2.e...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/utils/analysis.py
Add docstrings explaining edge cases
#!/usr/bin/env python3 # Copyright 2004-present Facebook. All Rights Reserved. import numpy as np from typing import List from annotator.oneformer.detectron2.config import CfgNode as CfgNode_ from annotator.oneformer.detectron2.config import configurable from .base_tracker import TRACKER_HEADS_REGISTRY from .vanilla...
--- +++ @@ -1,66 +1,102 @@-#!/usr/bin/env python3 -# Copyright 2004-present Facebook. All Rights Reserved. - -import numpy as np -from typing import List - -from annotator.oneformer.detectron2.config import CfgNode as CfgNode_ -from annotator.oneformer.detectron2.config import configurable - -from .base_tracker import ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/tracking/iou_weighted_hungarian_bbox_iou_tracker.py
Write docstrings including parameters and return values
# Copyright (c) Facebook, Inc. and its affiliates. import datetime import json import logging import os import time from collections import defaultdict from contextlib import contextmanager from typing import Optional import torch from fvcore.common.history_buffer import HistoryBuffer from annotator.oneformer.detectro...
--- +++ @@ -1,348 +1,534 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import datetime -import json -import logging -import os -import time -from collections import defaultdict -from contextlib import contextmanager -from typing import Optional -import torch -from fvcore.common.history_buffer import HistoryBuf...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/utils/events.py
Improve documentation using docstrings
# Copyright (c) Facebook, Inc. and its affiliates. import math import fvcore.nn.weight_init as weight_init import torch import torch.nn.functional as F from torch import nn from annotator.oneformer.detectron2.layers import Conv2d, ShapeSpec, get_norm from .backbone import Backbone from .build import BACKBONE_REGISTRY...
--- +++ @@ -1,203 +1,268 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import math -import fvcore.nn.weight_init as weight_init -import torch -import torch.nn.functional as F -from torch import nn - -from annotator.oneformer.detectron2.layers import Conv2d, ShapeSpec, get_norm - -from .backbone import Backbone...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/backbone/fpn.py
Write docstrings for utility functions
# Copyright (c) Facebook, Inc. and its affiliates. import importlib import importlib.util import logging import numpy as np import os import random import sys from datetime import datetime import torch __all__ = ["seed_all_rng"] TORCH_VERSION = tuple(int(x) for x in torch.__version__.split(".")[:2]) """ PyTorch vers...
--- +++ @@ -1,147 +1,170 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import importlib -import importlib.util -import logging -import numpy as np -import os -import random -import sys -from datetime import datetime -import torch - -__all__ = ["seed_all_rng"] - - -TORCH_VERSION = tuple(int(x) for x in torch.__...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/utils/env.py
Generate consistent documentation across files
# Copyright (c) Facebook, Inc. and its affiliates. from typing import List import torch from annotator.oneformer.detectron2.layers import nonzero_tuple # TODO: the name is too general class Matcher(object): def __init__( self, thresholds: List[float], labels: List[int], allow_low_quality_matches: bool =...
--- +++ @@ -1,70 +1,127 @@-# Copyright (c) Facebook, Inc. and its affiliates. -from typing import List -import torch - -from annotator.oneformer.detectron2.layers import nonzero_tuple - - -# TODO: the name is too general -class Matcher(object): - - def __init__( - self, thresholds: List[float], labels: List[i...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/matcher.py
Add docstrings to improve readability
import inspect import torch from annotator.oneformer.detectron2.utils.env import TORCH_VERSION try: from torch.fx._symbolic_trace import is_fx_tracing as is_fx_tracing_current tracing_current_exists = True except ImportError: tracing_current_exists = False try: from torch.fx._symbolic_trace import _...
--- +++ @@ -1,58 +1,71 @@-import inspect -import torch - -from annotator.oneformer.detectron2.utils.env import TORCH_VERSION - -try: - from torch.fx._symbolic_trace import is_fx_tracing as is_fx_tracing_current - - tracing_current_exists = True -except ImportError: - tracing_current_exists = False - -try: - ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/utils/tracing.py
Include argument descriptions in docstrings
# Copyright (c) Facebook, Inc. and its affiliates. import numpy as np from typing import List import annotator.oneformer.pycocotools.mask as mask_util from annotator.oneformer.detectron2.structures import Instances from annotator.oneformer.detectron2.utils.visualizer import ( ColorMode, Visualizer, _create...
--- +++ @@ -1,246 +1,287 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import numpy as np -from typing import List -import annotator.oneformer.pycocotools.mask as mask_util - -from annotator.oneformer.detectron2.structures import Instances -from annotator.oneformer.detectron2.utils.visualizer import ( - Col...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/utils/video_visualizer.py
Help me document legacy Python code
# -*- coding: utf-8 -*- # Copyright (c) Facebook, Inc. and its affiliates. import logging from typing import Dict, List import torch from torch import nn from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.structures import ImageList from ..postprocessing import detecto...
--- +++ @@ -1,203 +1,269 @@-# -*- coding: utf-8 -*- -# Copyright (c) Facebook, Inc. and its affiliates. - -import logging -from typing import Dict, List -import torch -from torch import nn - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detectron2.structures import ImageList ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/meta_arch/panoptic_fpn.py
Document this script properly
# -*- coding: utf-8 -*- # Copyright (c) Facebook, Inc. and its affiliates. import argparse import logging import os import sys import weakref from collections import OrderedDict from typing import Optional import torch from fvcore.nn.precise_bn import get_bn_modules from omegaconf import OmegaConf from torch.nn.paral...
--- +++ @@ -1,458 +1,715 @@-# -*- coding: utf-8 -*- -# Copyright (c) Facebook, Inc. and its affiliates. - - -import argparse -import logging -import os -import sys -import weakref -from collections import OrderedDict -from typing import Optional -import torch -from fvcore.nn.precise_bn import get_bn_modules -from omega...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/engine/defaults.py
Add docstrings for better understanding
# Copyright (c) Facebook, Inc. and its affiliates. import colorsys import logging import math import numpy as np from enum import Enum, unique import cv2 import matplotlib as mpl import matplotlib.colors as mplc import matplotlib.figure as mplfigure import annotator.oneformer.pycocotools.mask as mask_util import torch ...
--- +++ @@ -1,922 +1,1267 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import colorsys -import logging -import math -import numpy as np -from enum import Enum, unique -import cv2 -import matplotlib as mpl -import matplotlib.colors as mplc -import matplotlib.figure as mplfigure -import annotator.oneformer.pyco...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/utils/visualizer.py
Add docstrings to improve readability
# Copyright (c) Facebook, Inc. and its affiliates. import logging import numpy as np from typing import Dict, List, Optional, Tuple import torch from torch import nn from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.data.detection_utils import convert_image_to_rgb from ...
--- +++ @@ -1,249 +1,341 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import logging -import numpy as np -from typing import Dict, List, Optional, Tuple -import torch -from torch import nn - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneformer.detectron2.data.detection_uti...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/meta_arch/rcnn.py
Write docstrings describing each step
# Copyright (c) Facebook, Inc. and its affiliates. import math from typing import List, Tuple, Union import torch from fvcore.nn import giou_loss, smooth_l1_loss from torch.nn import functional as F from annotator.oneformer.detectron2.layers import cat, ciou_loss, diou_loss from annotator.oneformer.detectron2.structur...
--- +++ @@ -1,259 +1,369 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import math -from typing import List, Tuple, Union -import torch -from fvcore.nn import giou_loss, smooth_l1_loss -from torch.nn import functional as F - -from annotator.oneformer.detectron2.layers import cat, ciou_loss, diou_loss -from ann...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/modeling/box_regression.py
Document this module using docstrings
# Copyright (c) Facebook, Inc. and its affiliates. import atexit import functools import logging import os import sys import time from collections import Counter import torch from tabulate import tabulate from termcolor import colored from annotator.oneformer.detectron2.utils.file_io import PathManager __all__ = ["se...
--- +++ @@ -1,166 +1,237 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import atexit -import functools -import logging -import os -import sys -import time -from collections import Counter -import torch -from tabulate import tabulate -from termcolor import colored - -from annotator.oneformer.detectron2.utils.fi...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/utils/logger.py
Add docstrings for internal functions
# ------------------------------------------------------------------------- # MIT License # # Copyright (c) 2021 OpenAI # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, ...
--- +++ @@ -1,181 +1,192 @@-# ------------------------------------------------------------------------- -# MIT License -# -# Copyright (c) 2021 OpenAI -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/data/tokenizer.py
Generate consistent docstrings
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/data/datasets/register_ade20k_panoptic.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # ---------------------------------------------------...
--- +++ @@ -1,370 +1,394 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/data/datasets/register_ade20k_panoptic.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# --------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/data/datasets/register_ade20k_panoptic.py
Generate helpful docstrings for debugging
# Copyright (c) Facebook, Inc. and its affiliates. import copy import itertools import numpy as np from typing import Any, Iterator, List, Union import annotator.oneformer.pycocotools.mask as mask_util import torch from torch import device from annotator.oneformer.detectron2.layers.roi_align import ROIAlign from annot...
--- +++ @@ -1,339 +1,534 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import copy -import itertools -import numpy as np -from typing import Any, Iterator, List, Union -import annotator.oneformer.pycocotools.mask as mask_util -import torch -from torch import device - -from annotator.oneformer.detectron2.layers...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/structures/masks.py
Add structured docstrings to improve clarity
# Copyright (c) Facebook, Inc. and its affiliates. from typing import Callable, Dict, List, Optional, Tuple, Union import fvcore.nn.weight_init as weight_init import torch from torch import nn from torch.nn import functional as F from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.d...
--- +++ @@ -1,303 +1,348 @@-# Copyright (c) Facebook, Inc. and its affiliates. -from typing import Callable, Dict, List, Optional, Tuple, Union -import fvcore.nn.weight_init as weight_init -import torch -from torch import nn -from torch.nn import functional as F - -from annotator.oneformer.detectron2.config import conf...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/projects/deeplab/semantic_seg.py
Generate docstrings for this script
#!/usr/bin/env python3 # Copyright 2004-present Facebook. All Rights Reserved. import copy import numpy as np from typing import Dict import torch from scipy.optimize import linear_sum_assignment from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.structures import Boxes,...
--- +++ @@ -1,146 +1,171 @@-#!/usr/bin/env python3 -# Copyright 2004-present Facebook. All Rights Reserved. -import copy -import numpy as np -from typing import Dict -import torch -from scipy.optimize import linear_sum_assignment - -from annotator.oneformer.detectron2.config import configurable -from annotator.oneforme...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/tracking/hungarian_tracker.py
Replace inline comments with docstrings
# Copyright (c) Facebook, Inc. and its affiliates. import math from typing import List, Tuple import torch from annotator.oneformer.detectron2.layers.rotated_boxes import pairwise_iou_rotated from .boxes import Boxes class RotatedBoxes(Boxes): def __init__(self, tensor: torch.Tensor): device = tensor.d...
--- +++ @@ -1,195 +1,505 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import math -from typing import List, Tuple -import torch - -from annotator.oneformer.detectron2.layers.rotated_boxes import pairwise_iou_rotated - -from .boxes import Boxes - - -class RotatedBoxes(Boxes): - - def __init__(self, tensor: ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/structures/rotated_boxes.py
Write docstrings including parameters and return values
# -------------------------------------------------------- # Neighborhood Attention Transformer # Licensed under The MIT License # Written by Ali Hassani # -------------------------------------------------------- # Modified by Jitesh Jain import torch import torch.nn as nn from timm.models.layers import DropPath from...
--- +++ @@ -1,315 +1,324 @@-# -------------------------------------------------------- -# Neighborhood Attention Transformer -# Licensed under The MIT License -# Written by Ali Hassani -# -------------------------------------------------------- - -# Modified by Jitesh Jain - -import torch -import torch.nn as nn -from t...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/modeling/backbone/dinat.py
Add docstrings to make code maintainable
# Copyright (c) Facebook, Inc. and its affiliates. import fvcore.nn.weight_init as weight_init import torch.nn.functional as F from annotator.oneformer.detectron2.layers import CNNBlockBase, Conv2d, get_norm from annotator.oneformer.detectron2.modeling import BACKBONE_REGISTRY from annotator.oneformer.detectron2.model...
--- +++ @@ -1,145 +1,158 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import fvcore.nn.weight_init as weight_init -import torch.nn.functional as F - -from annotator.oneformer.detectron2.layers import CNNBlockBase, Conv2d, get_norm -from annotator.oneformer.detectron2.modeling import BACKBONE_REGISTRY -from an...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/detectron2/projects/deeplab/resnet.py
Improve documentation using docstrings
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/evaluation/evaluator.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # -----------------------------------------------------------------------...
--- +++ @@ -1,152 +1,228 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/evaluation/evaluator.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# ----------------------------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/evaluation/evaluator.py
Generate descriptive docstrings automatically
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/evaluation/coco_evaluation.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # -----------------------------------------------------------------...
--- +++ @@ -1,614 +1,723 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/evaluation/coco_evaluation.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# ----------------------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/evaluation/detection_coco_evaluator.py
Improve my code by adding docstrings
# -------------------------------------------------------- # Swin Transformer # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # Written by Ze Liu, Yutong Lin, Yixuan Wei # -------------------------------------------------------- # ----------------------------------------------...
--- +++ @@ -1,639 +1,771 @@-# -------------------------------------------------------- -# Swin Transformer -# Copyright (c) 2021 Microsoft -# Licensed under The MIT License [see LICENSE for details] -# Written by Ze Liu, Yutong Lin, Yixuan Wei -# -------------------------------------------------------- - -# -----------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/modeling/backbone/swin.py
Replace inline comments with docstrings
# ------------------------------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] # -------------------------------------------------------------------------...
--- +++ @@ -1,103 +1,120 @@-# ------------------------------------------------------------------------------------------------ -# Deformable DETR -# Copyright (c) 2020 SenseTime. All Rights Reserved. -# Licensed under the Apache License, Version 2.0 [see LICENSE for details] -# -----------------------------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/modeling/pixel_decoder/ops/modules/ms_deform_attn.py
Add structured docstrings to improve clarity
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/modeling/matcher.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # -------------------------------------------------------------------------...
--- +++ @@ -1,157 +1,212 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/modeling/matcher.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# ------------------------------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/modeling/matcher.py
Generate docstrings for this script
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/evaluation/instance_evaluation.py # ------------------------------------------------------------------------------ import contextlib import copy import io ...
--- +++ @@ -1,96 +1,110 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/evaluation/instance_evaluation.py -# ------------------------------------------------------------------------------ - -import co...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/evaluation/instance_evaluation.py
Add clean documentation to messy code
# -*- coding: utf-8 -*- # Copyright (c) Facebook, Inc. and its affiliates. from annotator.oneformer.detectron2.config import CfgNode as CN __all__ = ["add_common_config", "add_oneformer_config", "add_swin_config", "add_dinat_config", "add_beit_adapter_config", "add_convnext_config"] def add_common_config...
--- +++ @@ -1,221 +1,239 @@-# -*- coding: utf-8 -*- -# Copyright (c) Facebook, Inc. and its affiliates. -from annotator.oneformer.detectron2.config import CfgNode as CN - -__all__ = ["add_common_config", "add_oneformer_config", "add_swin_config", - "add_dinat_config", "add_beit_adapter_config", "add_convnex...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/config.py
Add docstrings with type hints explained
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/modeling/transformer_decoder/mask2former_transformer_decoder.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # -----------------------------...
--- +++ @@ -1,506 +1,528 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/modeling/transformer_decoder/mask2former_transformer_decoder.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/modeling/transformer_decoder/oneformer_transformer_decoder.py
Write docstrings for algorithm functions
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/modeling/transformer_decoder/position_encoding.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # -------------------------------------------...
--- +++ @@ -1,60 +1,67 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/modeling/transformer_decoder/position_encoding.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# --------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/modeling/transformer_decoder/position_encoding.py
Generate docstrings with examples
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/maskformer_model.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # -------------------------------------------------------------------------...
--- +++ @@ -1,419 +1,470 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/maskformer_model.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# ------------------------------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/oneformer_model.py
Write clean docstrings for readability
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/data/dataset_mappers/coco_panoptic_new_baseline_dataset_mapper.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # ---------------------------...
--- +++ @@ -1,306 +1,341 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/data/dataset_mappers/coco_panoptic_new_baseline_dataset_mapper.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3)...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/data/dataset_mappers/coco_unified_new_baseline_dataset_mapper.py
Add docstrings to clarify complex logic
# Copyright (c) Facebook, Inc. and its affiliates. from typing import Any, Callable, Dict, List, Optional, Union import torch.utils.data as torchdata from annotator.oneformer.detectron2.config import configurable from annotator.oneformer.detectron2.data.common import DatasetFromList, MapDataset from annotator.onefor...
--- +++ @@ -1,77 +1,117 @@-# Copyright (c) Facebook, Inc. and its affiliates. -from typing import Any, Callable, Dict, List, Optional, Union -import torch.utils.data as torchdata - -from annotator.oneformer.detectron2.config import configurable - - -from annotator.oneformer.detectron2.data.common import DatasetFromList...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/data/build.py
Add docstrings for utility scripts
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/modeling/transformer_decoder/transformer.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # -------------------------------------------------...
--- +++ @@ -1,367 +1,376 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/modeling/transformer_decoder/transformer.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# ------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/modeling/transformer_decoder/transformer.py
Write docstrings that follow conventions
import cv2 import numpy as np def nms(boxes, scores, nms_thr): x1 = boxes[:, 0] y1 = boxes[:, 1] x2 = boxes[:, 2] y2 = boxes[:, 3] areas = (x2 - x1 + 1) * (y2 - y1 + 1) order = scores.argsort()[::-1] keep = [] while order.size > 0: i = order[0] keep.append(i) x...
--- +++ @@ -2,6 +2,7 @@ import numpy as np def nms(boxes, scores, nms_thr): + """Single class NMS implemented in Numpy.""" x1 = boxes[:, 0] y1 = boxes[:, 1] x2 = boxes[:, 2] @@ -30,6 +31,7 @@ return keep def multiclass_nms(boxes, scores, nms_thr, score_thr): + """Multiclass NMS implemente...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/openpose/cv_ox_det.py
Generate docstrings for script automation
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/data/dataset_mapper.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # ------------------------------------------------------------------------...
--- +++ @@ -1,164 +1,203 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/data/dataset_mapper.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# -----------------------------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/data/dataset_mappers/dataset_mapper.py
Document helper functions with docstrings
__author__ = 'tsungyi' import numpy as np import datetime import time from collections import defaultdict from . import mask as maskUtils import copy class COCOeval: # Interface for evaluating detection on the Microsoft COCO dataset. # # The usage for CocoEval is as follows: # cocoGt=..., cocoDt=... ...
--- +++ @@ -58,6 +58,12 @@ # Code written by Piotr Dollar and Tsung-Yi Lin, 2015. # Licensed under the Simplified BSD License [see coco/license.txt] def __init__(self, cocoGt=None, cocoDt=None, iouType='segm'): + ''' + Initialize CocoEval using coco APIs for gt and dt + :param cocoGt:...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/pycocotools/cocoeval.py
Write proper docstrings for these functions
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/data/dataset_mappers/mask_former_panoptic_dataset_mapper.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # ---------------------------------...
--- +++ @@ -1,348 +1,375 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/data/dataset_mappers/mask_former_panoptic_dataset_mapper.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# --...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/data/dataset_mappers/oneformer_unified_dataset_mapper.py
Can you add docstrings to this Python file?
# Openpose # Original from CMU https://github.com/CMU-Perceptual-Computing-Lab/openpose # 2nd Edited by https://github.com/Hzzone/pytorch-openpose # 3rd Edited by ControlNet # 4th Edited by ControlNet (added face and correct hands) # 5th Edited by ControlNet (Improved JSON serialization/deserialization, and lots of bug...
--- +++ @@ -45,6 +45,20 @@ def draw_poses( poses: List[HumanPoseResult], H, W, draw_body=True, draw_hand=True, draw_face=True ): + """ + Draw the detected poses on an empty canvas. + + Args: + poses (List[HumanPoseResult]): A list of HumanPoseResult objects containing the detected poses. + ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/openpose/__init__.py
Generate consistent docstrings
from typing import List, Tuple import cv2 import numpy as np def preprocess( img: np.ndarray, out_bbox, input_size: Tuple[int, int] = (192, 256) ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: # get shape of image img_shape = img.shape[:2] out_img, out_center, out_scale = [], [], [] if len(out_bbo...
--- +++ @@ -6,6 +6,18 @@ def preprocess( img: np.ndarray, out_bbox, input_size: Tuple[int, int] = (192, 256) ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: + """Do preprocessing for DWPose model inference. + + Args: + img (np.ndarray): Input image in shape. + input_size (tuple): Input image s...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/openpose/cv_ox_pose.py
Write docstrings describing each step
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/evaluation/cityscapes_evaluation.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # -----------------------------------------------------------...
--- +++ @@ -1,172 +1,201 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/evaluation/cityscapes_evaluation.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# ----------------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/evaluation/cityscapes_evaluation.py
Add standardized docstrings across the file
# import pytorch import torch import torch.nn.functional as F @torch.jit.script def smish(input): return input * torch.tanh(torch.log(1+torch.sigmoid(input)))
--- +++ @@ -1,3 +1,9 @@+""" +Script based on: +Wang, Xueliang, Honge Ren, and Achuan Wang. + "Smish: A Novel Activation Function for Deep Learning Methods. + " Electronics 11.4 (2022): 540. +""" # import pytorch import torch @@ -6,4 +12,9 @@ @torch.jit.script def smish(input): + """ + Applies the mish func...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/teed/Fsmish.py
Add docstrings to meet PEP guidelines
# -------------------------------------------------------- # Position embedding utils # -------------------------------------------------------- from typing import Tuple import numpy as np import torch # -------------------------------------------------------- # 2D sine-cosine position embedding # References: # Tra...
--- +++ @@ -1,112 +1,122 @@-# -------------------------------------------------------- -# Position embedding utils -# -------------------------------------------------------- - -from typing import Tuple - -import numpy as np -import torch - - -# -------------------------------------------------------- -# 2D sine-cosine...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/utils/pos_embed.py
Add docstrings to meet PEP guidelines
# Copyright (c) Facebook, Inc. and its affiliates. # Modified by Bowen Cheng from https://github.com/facebookresearch/detr/blob/master/util/misc.py from typing import List, Optional import torch import torch.distributed as dist import torchvision from torch import Tensor import warnings import torch.nn.functional as F...
--- +++ @@ -1,176 +1,197 @@-# Copyright (c) Facebook, Inc. and its affiliates. -# Modified by Bowen Cheng from https://github.com/facebookresearch/detr/blob/master/util/misc.py -from typing import List, Optional - -import torch -import torch.distributed as dist -import torchvision -from torch import Tensor -import warn...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/utils/misc.py
Help me comply with documentation standards
# ------------------------------------------------------------------------------ # Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/evaluation/coco_evaluation.py # Modified by Jitesh Jain (https://github.com/praeclarumjj3) # -----------------------------------------------------------------...
--- +++ @@ -1,463 +1,563 @@-# ------------------------------------------------------------------------------ -# Reference: https://github.com/facebookresearch/detectron2/blob/main/detectron2/evaluation/coco_evaluation.py -# Modified by Jitesh Jain (https://github.com/praeclarumjj3) -# ----------------------------------...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/evaluation/coco_evaluator.py
Document functions with clear intent
# Copyright (c) Facebook, Inc. and its affiliates. import logging import numpy as np from typing import Callable, Dict, List, Optional, Tuple, Union import fvcore.nn.weight_init as weight_init import torch from torch import nn from torch.nn import functional as F from torch.nn.init import xavier_uniform_, constant_, u...
--- +++ @@ -1,288 +1,312 @@-# Copyright (c) Facebook, Inc. and its affiliates. -import logging -import numpy as np -from typing import Callable, Dict, List, Optional, Tuple, Union - -import fvcore.nn.weight_init as weight_init -import torch -from torch import nn -from torch.nn import functional as F -from torch.nn.init...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/modeling/pixel_decoder/fpn.py
Generate NumPy-style docstrings
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import torch, os from torchvision.ops.boxes import box_area def box_cxcywh_to_xyxy(x): x_c, y_c, w, h = x.unbind(-1) b = [(x_c - 0.5 * w), (y_c - 0.5 * h), (x_c + 0.5 * w), (y_c + 0.5 * h)] return torch.stack(b, dim=-1) def ...
--- +++ @@ -1,113 +1,133 @@-# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved -import torch, os -from torchvision.ops.boxes import box_area - - -def box_cxcywh_to_xyxy(x): - x_c, y_c, w, h = x.unbind(-1) - b = [(x_c - 0.5 * w), (y_c - 0.5 * h), - (x_c + 0.5 * w), (y_c + 0.5 * h)] - ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/utils/box_ops.py
Create docstrings for API functions
# import pytorch import torch import torch.nn.functional as F from torch import nn # import activation functions from .Fmish import mish class Mish(nn.Module): def __init__(self): super().__init__() def forward(self, input): if torch.__version__ >= "1.9": return F.mish(input) ...
--- +++ @@ -1,3 +1,7 @@+""" +Applies the mish function element-wise: +mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + exp(x))) +""" # import pytorch import torch @@ -9,11 +13,30 @@ class Mish(nn.Module): + """ + Applies the mish function element-wise: + mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/teed/Xmish.py
Add docstrings including usage examples
import math import numpy as np import matplotlib import cv2 from typing import List, Tuple, Union, Optional from .body import BodyResult, Keypoint eps = 0.01 def smart_resize(x, s): Ht, Wt = s if x.ndim == 2: Ho, Wo = x.shape Co = 1 else: Ho, Wo, Co = x.shape if Co == 3 or Co...
--- +++ @@ -79,6 +79,19 @@ def draw_bodypose(canvas: np.ndarray, keypoints: List[Keypoint]) -> np.ndarray: + """ + Draw keypoints and limbs representing body pose on a given canvas. + + Args: + canvas (np.ndarray): A 3D numpy array representing the canvas (image) on which to draw the body pose. ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/openpose/util.py
Write docstrings that follow conventions
import math import torch import torch.nn as nn import torch.nn.functional as F from modules import devices nets = { 'baseline': { 'layer0': 'cv', 'layer1': 'cv', 'layer2': 'cv', 'layer3': 'cv', 'layer4': 'cv', 'layer5': 'cv', 'layer6': 'cv', ...
--- +++ @@ -1,3 +1,7 @@+""" +Author: Zhuo Su, Wenzhe Liu +Date: Feb 18, 2021 +""" import math @@ -346,6 +350,9 @@ return self.pdc(input, self.weight, self.bias, self.stride, self.padding, self.dilation, self.groups) class CSAM(nn.Module): + """ + Compact Spatial Attention Module + """ def ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/pidinet/model.py
Add minimal docstrings for each function
import os import wandb from annotator.oneformer.detectron2.utils import comm from annotator.oneformer.detectron2.utils.events import EventWriter, get_event_storage def setup_wandb(cfg, args): if comm.is_main_process(): init_args = { k.lower(): v for k, v in cfg.WANDB.items() ...
--- +++ @@ -1,112 +1,120 @@-import os -import wandb -from annotator.oneformer.detectron2.utils import comm -from annotator.oneformer.detectron2.utils.events import EventWriter, get_event_storage - - -def setup_wandb(cfg, args): - if comm.is_main_process(): - init_args = { - k.lower(): v - ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/oneformer/utils/events.py
Add docstrings that explain purpose and usage
# import pytorch import torch import torch.nn.functional as F @torch.jit.script def mish(input): return input * torch.tanh(F.softplus(input))
--- +++ @@ -1,3 +1,6 @@+""" +Script provides functional interface for Mish activation function. +""" # import pytorch import torch @@ -6,4 +9,9 @@ @torch.jit.script def mish(input): + """ + Applies the mish function element-wise: + mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + exp(x))) + See addi...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/teed/Fmish.py
Add docstrings to incomplete code
# import pytorch import torch import torch.nn.functional as F from torch import nn # import activation functions from .Fsmish import smish class Smish(nn.Module): def __init__(self): super().__init__() def forward(self, input): return smish(input)
--- +++ @@ -1,3 +1,10 @@+""" +Script based on: +Wang, Xueliang, Honge Ren, and Achuan Wang. + "Smish: A Novel Activation Function for Deep Learning Methods. + " Electronics 11.4 (2022): 540. +smish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + sigmoid(x))) +""" # import pytorch import torch @@ -9,9 +16,28 @@ cla...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/teed/Xsmish.py
Improve documentation using docstrings
__author__ = 'tylin' __version__ = '2.0' # Interface for accessing the Microsoft COCO dataset. # Microsoft COCO is a large image dataset designed for object detection, # segmentation, and caption generation. annotator.oneformer.pycocotools is a Python API that # assists in loading, parsing and visualizing the annotati...
--- +++ @@ -66,6 +66,12 @@ class COCO: def __init__(self, annotation_file=None): + """ + Constructor of Microsoft COCO helper class for reading and visualizing annotations. + :param annotation_file (str): location of annotation file + :param image_folder (str): location to the folder ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/oneformer/pycocotools/coco.py
Provide docstrings following PEP 257
# MIT License import os # Copyright (c) 2022 Intelligent Systems Lab Org # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to us...
--- +++ @@ -1,336 +1,379 @@-# MIT License -import os - -# Copyright (c) 2022 Intelligent Systems Lab Org - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including wi...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/base_models/midas.py
Write Python docstrings for this snippet
import torch try: import mmcv as mmcv from mmcv.parallel import collate, scatter from mmcv.runner import load_checkpoint from mmseg.datasets.pipelines import Compose from mmseg.models import build_segmentor except ImportError: import annotator.mmpkg.mmcv as mmcv from annotator.mmpkg.mmcv.p...
--- +++ @@ -15,6 +15,18 @@ from annotator.mmpkg.mmseg.models import build_segmentor def init_segmentor(config, checkpoint=None, device='cuda:0'): + """Initialize a segmentor from config file. + + Args: + config (str or :obj:`mmcv.Config`): Config file path or the config + object. + ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/uniformer/inference.py
Add docstrings for better understanding
dependencies = ["torch"] import torch from midas.dpt_depth import DPTDepthModel from midas.midas_net import MidasNet from midas.midas_net_custom import MidasNet_small def DPT_BEiT_L_512(pretrained=True, **kwargs): model = DPTDepthModel( path=None, backbone="beitl16_512", non_...
--- +++ @@ -1,383 +1,435 @@-dependencies = ["torch"] - -import torch - -from midas.dpt_depth import DPTDepthModel -from midas.midas_net import MidasNet -from midas.midas_net_custom import MidasNet_small - -def DPT_BEiT_L_512(pretrained=True, **kwargs): - - model = DPTDepthModel( - path=None, - ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/base_models/midas_repo/hubconf.py
Help me document legacy Python code
import timm import torch import torch.nn as nn import numpy as np from .utils import activations, get_activation, Transpose def forward_levit(pretrained, x): pretrained.model.forward_features(x) layer_1 = pretrained.activations["1"] layer_2 = pretrained.activations["2"] layer_3 = pretrained.activati...
--- +++ @@ -1,96 +1,106 @@-import timm -import torch -import torch.nn as nn -import numpy as np - -from .utils import activations, get_activation, Transpose - - -def forward_levit(pretrained, x): - pretrained.model.forward_features(x) - - layer_1 = pretrained.activations["1"] - layer_2 = pretrained.activations...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/base_models/midas_repo/midas/backbones/levit.py
Document this code for team use
import torch import torch.nn as nn from .backbones.beit import ( _make_pretrained_beitl16_512, _make_pretrained_beitl16_384, _make_pretrained_beitb16_384, forward_beit, ) from .backbones.swin_common import ( forward_swin, ) from .backbones.swin2 import ( _make_pretrained_swin2l24_384, _make...
--- +++ @@ -1,368 +1,439 @@-import torch -import torch.nn as nn - -from .backbones.beit import ( - _make_pretrained_beitl16_512, - _make_pretrained_beitl16_384, - _make_pretrained_beitb16_384, - forward_beit, -) -from .backbones.swin_common import ( - forward_swin, -) -from .backbones.swin2 import ( - ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/base_models/midas_repo/midas/blocks.py
Add professional docstrings to my codebase
import os import glob import torch import utils import cv2 import argparse import time import numpy as np from imutils.video import VideoStream from midas.model_loader import default_models, load_model from modules import devices first_execution = True def process(device, model, model_type, image, input_size, targe...
--- +++ @@ -1,236 +1,279 @@-import os -import glob -import torch -import utils -import cv2 -import argparse -import time - -import numpy as np - -from imutils.video import VideoStream -from midas.model_loader import default_models, load_model - -from modules import devices - -first_execution = True -def process(device,...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/base_models/midas_repo/run.py
Add missing documentation to my Python functions
import os import glob import utils import cv2 import argparse import tensorflow as tf from transforms import Resize, NormalizeImage, PrepareForNet def run(input_path, output_path, model_path, model_type="large"): print("initialize") # the runtime initialization will not allocate all memory on the device to ...
--- +++ @@ -1,126 +1,135 @@-import os -import glob -import utils -import cv2 -import argparse - -import tensorflow as tf - -from transforms import Resize, NormalizeImage, PrepareForNet - -def run(input_path, output_path, model_path, model_type="large"): - print("initialize") - - # the runtime initialization will ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/base_models/midas_repo/tf/run_pb.py
Generate consistent docstrings
import sys import re import numpy as np import cv2 import torch def read_pfm(path): with open(path, "rb") as file: color = None width = None height = None scale = None endian = None header = file.readline().rstrip() if header.decode("ascii") == "PF": ...
--- +++ @@ -1,149 +1,199 @@-import sys -import re -import numpy as np -import cv2 -import torch - - -def read_pfm(path): - with open(path, "rb") as file: - - color = None - width = None - height = None - scale = None - endian = None - - header = file.readline().rstrip() - ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/base_models/midas_repo/utils.py
Create docstrings for all classes and functions
import numpy as np import sys import cv2 def write_pfm(path, image, scale=1): with open(path, "wb") as file: color = None if image.dtype.name != "float32": raise Exception("Image dtype must be float32.") image = np.flipud(image) if len(image.shape) == 3 and image.sh...
--- +++ @@ -1,65 +1,82 @@-import numpy as np -import sys -import cv2 - - -def write_pfm(path, image, scale=1): - - with open(path, "wb") as file: - color = None - - if image.dtype.name != "float32": - raise Exception("Image dtype must be float32.") - - image = np.flipud(image) - - ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/base_models/midas_repo/tf/utils.py
Document my Python code with docstrings
# MIT License # Copyright (c) 2022 Intelligent Systems Lab Org # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, m...
--- +++ @@ -1,65 +1,91 @@-# MIT License - -# Copyright (c) 2022 Intelligent Systems Lab Org - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitat...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/layers/patch_transformer.py
Turn comments into proper docstrings
# MIT License # Copyright (c) 2022 Intelligent Systems Lab Org # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, m...
--- +++ @@ -1,85 +1,121 @@-# MIT License - -# Copyright (c) 2022 Intelligent Systems Lab Org - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limita...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/layers/dist_layers.py
Add docstrings to my Python code
# MIT License # Copyright (c) 2022 Intelligent Systems Lab Org # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, m...
--- +++ @@ -1,71 +1,92 @@-# MIT License - -# Copyright (c) 2022 Intelligent Systems Lab Org - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitat...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/model_io.py
Provide docstrings following PEP 257
# MIT License # Copyright (c) 2022 Intelligent Systems Lab Org # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, m...
--- +++ @@ -1,165 +1,208 @@-# MIT License - -# Copyright (c) 2022 Intelligent Systems Lab Org - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limit...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/layers/attractor.py
Add docstrings for internal functions
# MIT License # Copyright (c) 2022 Intelligent Systems Lab Org # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, m...
--- +++ @@ -1,206 +1,250 @@-# MIT License - -# Copyright (c) 2022 Intelligent Systems Lab Org - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limit...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/zoedepth/zoedepth_v1.py
Insert docstrings into my code
# MIT License # Copyright (c) 2022 Intelligent Systems Lab Org # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, m...
--- +++ @@ -1,311 +1,368 @@-# MIT License - -# Copyright (c) 2022 Intelligent Systems Lab Org - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limit...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/utils/misc.py
Turn comments into proper docstrings
class EasyDict(dict): def __init__(self, d=None, **kwargs): if d is None: d = {} else: d = dict(d) if kwargs: d.update(**kwargs) for k, v in d.items(): setattr(self, k, v) # Class attributes for k in self.__clas...
--- +++ @@ -1,41 +1,158 @@- -class EasyDict(dict): - def __init__(self, d=None, **kwargs): - if d is None: - d = {} - else: - d = dict(d) - if kwargs: - d.update(**kwargs) - for k, v in d.items(): - setattr(self, k, v) - # Class a...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/utils/easydict/__init__.py
Generate docstrings for each module
# MIT License # Copyright (c) 2022 Intelligent Systems Lab Org # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, m...
--- +++ @@ -1,396 +1,437 @@-# MIT License - -# Copyright (c) 2022 Intelligent Systems Lab Org - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limit...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/utils/config.py
Generate documentation strings for clarity
# MIT License # Copyright (c) 2022 Intelligent Systems Lab Org # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, m...
--- +++ @@ -1,83 +1,98 @@-# MIT License - -# Copyright (c) 2022 Intelligent Systems Lab Org - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitat...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/utils/geometry.py
Improve my code by adding docstrings
from copy import copy from typing import List, Any, Optional, Union, Tuple, Dict import numpy as np from modules import scripts, processing, shared from modules.api import api from .args import ControlNetUnit from scripts import global_state from scripts.logging import logger from scripts.enums import ( ResizeMode...
--- +++ @@ -70,6 +70,30 @@ target_W: int, resize_mode: ResizeMode, ) -> int: + """ + Calculate the estimated resolution for resizing an image while preserving aspect ratio. + + The function first calculates scaling factors for height and width of the image based on the target + height and width. T...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/internal_controlnet/external_code.py
Write proper docstrings for these functions
import torch import torch.nn as nn from collections import OrderedDict from copy import deepcopy from modules import devices cond_cast_unet = getattr(devices, 'cond_cast_unet', lambda x: x) class TorchHijackForUnet: def __getattr__(self, item): if item == 'cat': return self.cat if h...
--- +++ @@ -8,6 +8,10 @@ class TorchHijackForUnet: + """ + This is torch, but with cat that resizes tensors to appropriate dimensions if they do not match; + this makes it possible to create pictures with dimensions that are multiples of 8 rather than 64 + """ def __getattr__(self, item): ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/scripts/adapter.py
Create structured documentation for my script
import launch from importlib import metadata import sys import os import shutil import platform from pathlib import Path from typing import Optional from packaging.version import parse repo_root = Path(__file__).parent main_req_file = repo_root / "requirements.txt" def get_installed_version(package: str) -> Optiona...
--- +++ @@ -71,6 +71,10 @@ def install_onnxruntime(): + """ + Install onnxruntime or onnxruntime-gpu based on the availability of CUDA. + onnxruntime and onnxruntime-gpu can not be installed together. + """ if not launch.is_installed("onnxruntime") and not launch.is_installed("onnxruntime-gpu"): ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/install.py
Add docstrings to make code maintainable
# 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...
--- +++ @@ -47,6 +47,21 @@ def load_state_dict(module, state_dict, strict=False, logger=None): + """Load state_dict to a module. + + This method is modified from :meth:`torch.nn.Module.load_state_dict`. + Default value for ``strict`` is set to ``False`` and the message for + param mismatch will be shown...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/uniformer/mmcv_custom/checkpoint.py
Annotate my code with docstrings
# -------------------------------------------------------- # UniFormer # Copyright (c) 2022 SenseTime X-Lab # Licensed under The MIT License [see LICENSE for details] # Written by Kunchang Li # -------------------------------------------------------- import torch import torch.nn as nn import torch.nn.functional as F ...
--- +++ @@ -140,6 +140,13 @@ def window_partition(x, window_size): + """ + Args: + x: (B, H, W, C) + window_size (int): window size + Returns: + windows: (num_windows*B, window_size, window_size, C) + """ B, H, W, C = x.shape x = x.view(B, H // window_size, window_size, W ...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/uniformer/uniformer.py
Add docstrings that explain purpose and usage
import timm import torch import types import numpy as np import torch.nn.functional as F from .utils import forward_adapted_unflatten, make_backbone_default from timm.models.beit import gen_relative_position_index from torch.utils.checkpoint import checkpoint from typing import Optional def forward_beit(pretrained,...
--- +++ @@ -1,183 +1,198 @@-import timm -import torch -import types - -import numpy as np -import torch.nn.functional as F - -from .utils import forward_adapted_unflatten, make_backbone_default -from timm.models.beit import gen_relative_position_index -from torch.utils.checkpoint import checkpoint -from typing import O...
https://raw.githubusercontent.com/Mikubill/sd-webui-controlnet/HEAD/annotator/zoe/zoedepth/models/base_models/midas_repo/midas/backbones/beit.py