Spaces:
Running
Running
Huang commited on
Commit ·
6a80886
1
Parent(s): 2eb5b9e
orgin
Browse filesFiles changed (8)
- annotator/__init__.py+3-1
- annotator/denthPose/Base-DensePose-RCNN-FPN.yamlAdded+48
- annotator/denthPose/__init__.pyAdded+20
- annotator/denthPose/densepose_rcnn_R_50_FPN_s1x.pklAdded+3
- annotator/denthPose/densepose_rcnn_R_50_FPN_s1x.yamlAdded+9
- annotator/denthPose/depth_pose.pyAdded+114
- annotator/denthPose/readme.mdAdded+10
- config/annotator.yaml+3
15 unmodified lines16171819202112 unmodified lines3435363738394015 unmodified linesfrom .shuffle import Image2MaskShuffleDetectorfrom .zoe import ZoeDetectorfrom .oneformer import OneformerDetector__all__ = [UniformerDetector,12 unmodified linesPidInet,Image2MaskShuffleDetector,ZoeDetector,OneformerDetector]##15 unmodified lines1617181920212212 unmodified lines353637383940414215 unmodified linesfrom .shuffle import Image2MaskShuffleDetectorfrom .zoe import ZoeDetectorfrom .oneformer import OneformerDetectorfrom .denthPose import DenthPoseProcessor__all__ = [UniformerDetector,12 unmodified linesPidInet,Image2MaskShuffleDetector,ZoeDetector,OneformerDetector,DenthPoseProcessor]##
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748VERSION: 2MODEL: META_ARCHITECTURE: "GeneralizedRCNN" BACKBONE: NAME: "build_resnet_fpn_backbone" RESNETS: OUT_FEATURES: ["res2", "res3", "res4", "res5"] FPN: IN_FEATURES: ["res2", "res3", "res4", "res5"] ANCHOR_GENERATOR: SIZES: [[32], [64], [128], [256], [512]] # One size for each in feature map ASPECT_RATIOS: [[0.5, 1.0, 2.0]] # Three aspect ratios (same for all in feature maps) RPN: IN_FEATURES: ["p2", "p3", "p4", "p5", "p6"] PRE_NMS_TOPK_TRAIN: 2000 # Per FPN level PRE_NMS_TOPK_TEST: 1000 # Per FPN level # Detectron1 uses 2000 proposals per-batch, # (See "modeling/rpn/rpn_outputs.py" for details of this legacy issue) # which is approximately 1000 proposals per-image since the default batch size for FPN is 2. POST_NMS_TOPK_TRAIN: 1000 POST_NMS_TOPK_TEST: 1000
DENSEPOSE_ON: True ROI_HEADS: NAME: "DensePoseROIHeads" IN_FEATURES: ["p2", "p3", "p4", "p5"] NUM_CLASSES: 1 ROI_BOX_HEAD: NAME: "FastRCNNConvFCHead" NUM_FC: 2 POOLER_RESOLUTION: 7 POOLER_SAMPLING_RATIO: 2 POOLER_TYPE: "ROIAlign" ROI_DENSEPOSE_HEAD: NAME: "DensePoseV1ConvXHead" POOLER_TYPE: "ROIAlign" NUM_COARSE_SEGM_CHANNELS: 2DATASETS: TRAIN: ("densepose_coco_2014_train", "densepose_coco_2014_valminusminival") TEST: ("densepose_coco_2014_minival",)SOLVER: IMS_PER_BATCH: 16 BASE_LR: 0.01 STEPS: (60000, 80000) MAX_ITER: 90000 WARMUP_FACTOR: 0.1INPUT: MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800)1234567891011121314151617181920import os
def install_package(): print(os.system("pip install git+https://github.com/facebookresearch/detectron2.git")) print(os.system("pip install git+https://github.com/facebookresearch/detectron2@main#subdirectory=projects/DensePose"))
install_package()
print("finished")
class DenthPoseProcessor: def __init__(self): from .depth_pose import DenthPoseProcess self.processor = DenthPoseProcess()
def __call__(self, img): return self.processor(img)123version https://git-lfs.github.com/spec/v1oid sha256:b8a7382001b16e453bad95ca9dbc68ae8f2b839b304cf90eaf5c27fbdb4dae91size 255757821123456789_BASE_: "Base-DensePose-RCNN-FPN.yaml"MODEL: WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" RESNETS: DEPTH: 50 DEVICE: "cpu"SOLVER: MAX_ITER: 130000 STEPS: (100000, 120000)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114import os.pathfrom os import pathfrom typing import List, Dict, Any, ClassVar
import torchfrom densepose import add_densepose_configfrom densepose.vis.base import CompoundVisualizerfrom densepose.vis.bounding_box import ScoredBoundingBoxVisualizerfrom densepose.vis.densepose_outputs_vertex import get_texture_atlases, DensePoseOutputsTextureVisualizer, \ DensePoseOutputsVertexVisualizerfrom densepose.vis.densepose_results import DensePoseResultsContourVisualizer, \ DensePoseResultsFineSegmentationVisualizer, DensePoseResultsUVisualizer, DensePoseResultsVVisualizerfrom densepose.vis.densepose_results_textures import get_texture_atlas, DensePoseResultsVisualizerWithTexturefrom densepose.vis.extractor import create_extractor, CompoundExtractorfrom detectron2.config import CfgNode, get_cfgfrom detectron2.engine.defaults import DefaultPredictor
from annotator.base_annotator import BaseProcessor
config_model = { "densepose_rcnn_R_50_FPN_s1x": { "yaml": 'densepose_rcnn_R_50_FPN_s1x.yaml', "file": "densepose_rcnn_R_50_FPN_s1x.pkl" }}
default_conf = config_model["densepose_rcnn_R_50_FPN_s1x"]
class DenthPoseProcess(BaseProcessor): VISUALIZERS: ClassVar[Dict[str, object]] = { "dp_contour": DensePoseResultsContourVisualizer, "dp_segm": DensePoseResultsFineSegmentationVisualizer, "dp_u": DensePoseResultsUVisualizer, "dp_v": DensePoseResultsVVisualizer, "dp_iuv_texture": DensePoseResultsVisualizerWithTexture, "dp_cse_texture": DensePoseOutputsTextureVisualizer, "dp_vertex": DensePoseOutputsVertexVisualizer, "bbox": ScoredBoundingBoxVisualizer, }
def __init__(self, **kwargs): super().__init__(**kwargs) here = path.abspath(path.dirname(__file__)) self.cfg, self.model_conf = os.path.join(here, default_conf["yaml"]), os.path.join(here, default_conf["file"]) self.predictor = None
@classmethod def setup_config( cls: type, config_fpath: str, model_fpath: str, opts: List[str] ): cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(config_fpath) if opts: cfg.merge_from_list(opts) cfg.MODEL.WEIGHTS = model_fpath cfg.freeze() return cfg
@classmethod def create_context(cls: type, vis_specs, cfg: CfgNode, arg_texture_atlas=None, arg_texture_atlases_map=None) -> \ Dict[ str, Any]: """ 创建可视化 """ # vis_specs = visualizations.split(",") visualizers = [] extractors = [] for vis_spec in vis_specs: texture_atlas = get_texture_atlas(arg_texture_atlas) texture_atlases_dict = get_texture_atlases(arg_texture_atlases_map) vis = cls.VISUALIZERS[vis_spec]( cfg=cfg, texture_atlas=texture_atlas, texture_atlases_dict=texture_atlases_dict, ) visualizers.append(vis) extractor = create_extractor(vis) extractors.append(extractor) visualizer = CompoundVisualizer(visualizers) extractor = CompoundExtractor(extractors) context = { "extractor": extractor, "visualizer": visualizer, "entry_idx": 0, } return context
def execute_on_outputs(self, image, context: Dict[str, Any], outputs): visualizer = context["visualizer"] extractor = context["extractor"] # image = np.tile(image[:, :, np.newaxis], [1, 1, 3]) data = extractor(outputs) # zero_image = np.zeros(image.shape, dtype=np.uint8) image_vis = visualizer.visualize(image, data) return image_vis
def __call__(self, img, visualizations=["dp_u", "dp_v", "bbox"], texture_atlas=None, texture_atlases_map=None): opts = [] cfg = self.setup_config(config_fpath=self.cfg, model_fpath=self.model_conf, opts=opts) if self.predictor is None: self.predictor = DefaultPredictor(cfg) context = self.create_context(visualizations, cfg, texture_atlas, texture_atlases_map) with torch.no_grad(): outputs = self.predictor(img)["instances"] return self.execute_on_outputs(img, context, outputs)
# if __name__ == '__main__':# image_path = "demo.jpeg"# img = cv2.imread(image_path)# process = DenthPoseProcessor()# process(img, "dp_contour,bbox")12345678910### 安装 detectron2pip install 'git+https://github.com/facebookresearch/detectron2.git'
### 安装 DensePosepip install git+https://github.com/facebookresearch/detectron2@main#subdirectory=projects/DensePose
#python apply_net.py show densepose_rcnn_R_50_FPN_s1x.yaml model_final_162be9.pkl demo.jpg dp_contour,bbox --output image_densepose_contour.png
122 unmodified lines123124125122 unmodified linesoneformer:process: OneformerDetectorinput: []122 unmodified lines123124125126127128122 unmodified linesoneformer:process: OneformerDetectorinput: []denthPose:process: DenthPoseProcessorinput: []
annotator/__init__.py+3-1
annotator/denthPose/Base-DensePose-RCNN-FPN.yamlAdded+48
annotator/denthPose/__init__.pyAdded+20
annotator/denthPose/densepose_rcnn_R_50_FPN_s1x.pklAdded+3
annotator/denthPose/densepose_rcnn_R_50_FPN_s1x.yamlAdded+9
annotator/denthPose/depth_pose.pyAdded+114
annotator/denthPose/readme.mdAdded+10
config/annotator.yaml+3