Comments (13)
I successfully trained a model on my own dataset.
Firstly I create two own datasets in coco format:
- for test
./centermask2/datasets/numberplate/val/coco_numberplate.json
./centermask2/datasets/numberplate/val/*.jpeg - for train
./centermask2/datasets/numberplate/train/coco_numberplate.json
./centermask2/datasets/numberplate/train/*.jpeg
Than I create own config files for model with 2 classes BACKGROUND and NUMBERPLATE in dir ./centermask2/configs/numberplates
- numberplate_V_39_eSE_FPN_ms_3x.yaml
_BASE_: "Base-NumberPlate-VoVNet.yaml"
MODEL:
WEIGHTS: "https://www.dropbox.com/s/q98pypf96rhtd8y/vovnet39_ese_detectron2.pth?dl=1"
VOVNET:
CONV_BODY : "V-39-eSE"
SOLVER:
STEPS: (0, 60000)
MAX_ITER: 60000
OUTPUT_DIR: "output/numberplate/numberplate-V-39-ms-3x"
- Base-NumberPlate-VoVNet.yaml
_MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
BACKBONE:
NAME: "build_fcos_vovnet_fpn_backbone"
FREEZE_AT: 0
VOVNET:
OUT_FEATURES: ["stage3", "stage4", "stage5"]
FPN:
IN_FEATURES: ["stage3", "stage4", "stage5"]
PROPOSAL_GENERATOR:
NAME: "FCOS"
FCOS:
POST_NMS_TOPK_TEST: 50
# PIXEL_MEAN: [102.9801, 115.9465, 122.7717]
MASK_ON: True
MASKIOU_ON: True
ROI_HEADS:
NAME: "CenterROIHeads"
IN_FEATURES: ["p3", "p4", "p5"]
ROI_MASK_HEAD:
NAME: "SpatialAttentionMaskHead"
ASSIGN_CRITERION: "ratio"
NUM_CONV: 4
POOLER_RESOLUTION: 14
DATASETS:
TRAIN: ("numberplate_train",)
TEST: ("numberplate_val",)
SOLVER:
CHECKPOINT_PERIOD: 6000
IMS_PER_BATCH: 16
BASE_LR: 0.01 # Note that RetinaNet uses a different default learning rate
STEPS: (0, 60000)
MAX_ITER: 60000
INPUT:
MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800)
After that I added to the file ./centermask2/train_net.py in the section main the registration of my own dataset:
# Regist own dataset.
from detectron2.data.datasets import register_coco_instances
# train data
name = "numberplate_train"
json_file = "/var/www/centermask2/datasets/numberplate/train/coco_numberplate.json"
image_root = "/var/www/centermask2/datasets/numberplate/train"
# test data
name_val = "numberplate_val"
json_file_val = "./centermask2/datasets/numberplate/val/coco_numberplate.json"
image_root_val = "./centermask2/datasets/numberplate/val"
# registr
register_coco_instances(name, {}, json_file, image_root)
register_coco_instances(name_val, {}, json_file_val, image_root_val)
In the end, I ran the command line:
DETECTRON2_DATASETS=./centermask2/datasets python3 train_net.py --config-file "configs/numberplates/numberplate_V_39_eSE_FPN_ms_3x.yaml" --num-gpus 1
from centermask2.
for prediction on own dataset I use simple script
import os
import time
import glob
import numpy as np
from matplotlib import pyplot as plt
from detectron2.engine import DefaultPredictor, default_argument_parser, default_setup, launch
from centermask.config import get_cfg
def setup(args):
"""
Create configs and perform basic setups.
"""
cfg = get_cfg()
cfg.merge_from_file(args.config_file)
cfg.merge_from_list(args.opts)
cfg.freeze()
default_setup(cfg, args)
return cfg
def main(args):
cfg = setup(args)
outputs_cpu = []
predictor = DefaultPredictor(cfg)
for file_name in glob.glob("./images/*"):
im = plt.imread(file_name)
start_time = time.time()
outputs = predictor(im)
output_cpu = outputs["instances"].to("cpu")
print(f"[TIME] {time.time() - start_time}s")
for i, mask in enumerate(np.array(output_cpu.get_fields()["pred_masks"])):
plt.imsave(f"./masks/{os.path.basename(file_name)}_mask_{i}.png", mask*255)
outputs_cpu.append(output_cpu)
return output_cpu
if __name__ == "__main__":
args = default_argument_parser().parse_args()
print("Command Line Args:", args)
# Regist own dataset.
from detectron2.data.datasets import register_coco_instances
# train data
name = "numberplate_train"
json_file = "/var/www/centermask2/datasets/numberplate/train/coco_numberplate.json"
image_root = "/var/www/centermask2/datasets/numberplate/train"
# test data
name_val = "numberplate_val"
json_file_val = "/var/www/centermask2/datasets/numberplate/val/coco_numberplate.json"
image_root_val = "/var/www/centermask2/datasets/numberplate/val"
# registr
register_coco_instances(name, {}, json_file, image_root)
register_coco_instances(name_val, {}, json_file_val, image_root_val)
launch(
main,
args.num_gpus,
num_machines=args.num_machines,
machine_rank=args.machine_rank,
dist_url=args.dist_url,
args=(args,),
)
run script
python3 predict_net.py --config-file "./configs/numberplates/numberplate_V_39_eSE_FPN_ms_3x.yaml" MODEL.WEIGHTS .//output/numberplate/numberplate-V-39-ms-3x/model_0023999.pth
In this case, only 1 GPU is used.
If you want to run on more GPUs, use AsyncPredictor instead of DefaultPredictor
from centermask2.
need to change the ./centermask/config/defaults.py file ?
like :
cfg.MODEL.ROI_HEADS.NUM_CLASSES = num_classes
cfg.MODEL.SEM_SEG_HEAD.NUM_CLASSES = num_classes
cfg.MODEL.RETINANET.NUM_CLASSES = num_classes
cfg.MODEL.FCOS.NUM_CLASSES = num_classes
??
from centermask2.
It seems that if own datasets only has one class, the NUM_CLASSES
should be 2 which contains background.
When training with my own datasets, if this value set as 1 , the loss will be very small and quickly decreases to 0. If this value set as 2, the loss seems normal.
from centermask2.
Yes, except for cfg.MODEL.RETINANET.NUM_CLASSES = num_classes
from centermask2.
Yes, except for
cfg.MODEL.RETINANET.NUM_CLASSES = num_classes
thanks for that ,i can only find _C.MODEL.FCOS.NUM_CLASSES in defaults.py and i change it from 80 to 1
however, i can not find the others:
cfg.MODEL.ROI_HEADS.NUM_CLASSES
cfg.MODEL.SEM_SEG_HEAD.NUM_CLASSES
which file should i find ?
from centermask2.
you just insert the config option in config file (.yaml) or command line.
For example,
python train_net.py --config-file <config.yaml> --num-gpus 8 MODEL.ROI_HEADS.NUM_CLASSES 1
from centermask2.
/numberplate/train/coco_numberplate.json" image_root = "/var/www/centermask2/datasets/numberplate/train"
Is it required to include the .npy files of the masks in the train folder?
I am confused here; when I only include the .jpeg files of the input images and the .json file of the annotations, I get an error like this:
No such file or directory: '/datasets/new/train/image_000000.npy
and when I include the .npy files, the error is:
cannot identify image file <_io.BufferedReader name='/datasets/new/train/image_000000.npy'
from centermask2.
Please how can i predict with the model that i train?
plaise help me
from centermask2.
I successfully trained a model on my own dataset.
Firstly I create two own datasets in coco format:
- for test
./centermask2/datasets/numberplate/val/coco_numberplate.json
./centermask2/datasets/numberplate/val/*.jpeg- for train
./centermask2/datasets/numberplate/train/coco_numberplate.json
./centermask2/datasets/numberplate/train/*.jpegThan I create own config files for model with 2 classes BACKGROUND and NUMBERPLATE in dir ./centermask2/configs/numberplates
- numberplate_V_39_eSE_FPN_ms_3x.yaml
_BASE_: "Base-NumberPlate-VoVNet.yaml" MODEL: WEIGHTS: "https://www.dropbox.com/s/q98pypf96rhtd8y/vovnet39_ese_detectron2.pth?dl=1" VOVNET: CONV_BODY : "V-39-eSE" SOLVER: STEPS: (0, 60000) MAX_ITER: 60000 OUTPUT_DIR: "output/numberplate/numberplate-V-39-ms-3x"
- Base-NumberPlate-VoVNet.yaml
_MODEL: META_ARCHITECTURE: "GeneralizedRCNN" BACKBONE: NAME: "build_fcos_vovnet_fpn_backbone" FREEZE_AT: 0 VOVNET: OUT_FEATURES: ["stage3", "stage4", "stage5"] FPN: IN_FEATURES: ["stage3", "stage4", "stage5"] PROPOSAL_GENERATOR: NAME: "FCOS" FCOS: POST_NMS_TOPK_TEST: 50 # PIXEL_MEAN: [102.9801, 115.9465, 122.7717] MASK_ON: True MASKIOU_ON: True ROI_HEADS: NAME: "CenterROIHeads" IN_FEATURES: ["p3", "p4", "p5"] ROI_MASK_HEAD: NAME: "SpatialAttentionMaskHead" ASSIGN_CRITERION: "ratio" NUM_CONV: 4 POOLER_RESOLUTION: 14 DATASETS: TRAIN: ("numberplate_train",) TEST: ("numberplate_val",) SOLVER: CHECKPOINT_PERIOD: 6000 IMS_PER_BATCH: 16 BASE_LR: 0.01 # Note that RetinaNet uses a different default learning rate STEPS: (0, 60000) MAX_ITER: 60000 INPUT: MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800)After that I added to the file ./centermask2/train_net.py in the section main the registration of my own dataset:
# Regist own dataset. from detectron2.data.datasets import register_coco_instances # train data name = "numberplate_train" json_file = "/var/www/centermask2/datasets/numberplate/train/coco_numberplate.json" image_root = "/var/www/centermask2/datasets/numberplate/train" # test data name_val = "numberplate_val" json_file_val = "./centermask2/datasets/numberplate/val/coco_numberplate.json" image_root_val = "./centermask2/datasets/numberplate/val" # registr register_coco_instances(name, {}, json_file, image_root) register_coco_instances(name_val, {}, json_file_val, image_root_val)In the end, I ran the command line:
DETECTRON2_DATASETS=./centermask2/datasets python3 train_net.py --config-file "configs/numberplates/numberplate_V_39_eSE_FPN_ms_3x.yaml" --num-gpus 1
Hello @dimabendera,
Thanks for the information.
I am implementing centermask2 on my custom data as well. All your steps have been helpful. I just wanted to know in which format did you register your annotations? Everything seems to work if the segmentation mask is in polygon format but I am having a problem while working with the mask in RLE format? Could you provide some information regarding the same?
from centermask2.
It seems that if own datasets only has one class, the
NUM_CLASSES
should be 2 which contains background.
When training with my own datasets, if this value set as 1 , the loss will be very small and quickly decreases to 0. If this value set as 2, the loss seems normal.
you are right. If the dataset contains 2 classes. so we have to set these params to 3: 2 classes + background
ALSO!! don't forget to do the same definition when you run predict.py
from centermask2.
you just insert the config option in config file (.yaml) or command line.
For example,
python train_net.py --config-file <config.yaml> --num-gpus 8 MODEL.ROI_HEADS.NUM_CLASSES 1
But how could I config in the config-file (.yaml), is there any format for that
from centermask2.
Hello everyone
I am trying to implement CenterMask2 https://github.com/youngwanLEE/centermask2 which makes use of Detectron2.
My annotations are in COCO RLE format, my data registration is successful. I visualized the data as well using the detectron2 visualizer, also I have set cfg.INPUT.MASk_FORMAT= bitmask, but somehow this error is being raised while I try to train the network.
Can somebody help me out here with what could be done?
File "train_net.py", line 181, in <module>
launch(
File "/workspace/detectron2/detectron2/engine/launch.py", line 84, in launch
main_func(*args)
File "train_net.py", line 151, in main
return trainer.train()
File "/workspace/detectron2/detectron2/engine/defaults.py", line 484, in train
super().train(self.start_iter, self.max_iter)
File "/workspace/detectron2/detectron2/engine/train_loop.py", line 155, in train
self.run_step()
File "/workspace/detectron2/detectron2/engine/defaults.py", line 494, in run_step
self._trainer.run_step()
File "/workspace/detectron2/detectron2/engine/train_loop.py", line 287, in run_step
loss_dict = self.model(data)
File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/workspace/detectron2/detectron2/modeling/meta_arch/rcnn.py", line 167, in forward
_, detector_losses = self.roi_heads(images, features, proposals, gt_instances)
File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/workspace/centermask2/centermask/modeling/centermask/center_heads.py", line 401, in forward
losses, mask_features, selected_mask, labels, maskiou_targets = self._forward_mask(features, proposals)
File "/workspace/centermask2/centermask/modeling/centermask/center_heads.py", line 476, in _forward_mask
loss, selected_mask, labels, maskiou_targets = mask_rcnn_loss(mask_logits, proposals, self.maskiou_on)
File "/workspace/centermask2/centermask/modeling/centermask/mask_head.py", line 80, in mask_rcnn_loss
cropped_mask = crop(instances_per_image.gt_masks.polygons, instances_per_image.proposal_boxes.tensor)
AttributeError: 'BitMasks' object has no attribute 'polygons'
from centermask2.
Related Issues (20)
- FCOS
- AttributeError: 'BitMasks' object has no attribute 'polygons'
- where can I find mask_rcnn_R_50_FPN_inference_acc_test.yaml
- Anyone succeed in converting pth to onnx format? HOT 1
- Anyone succeed in converting pth model to onnx format? HOT 2
- The gap between the results of our training centermask_R_101_FPN_ms_3x.yaml and the record of the paper HOT 4
- i am not familiar with detectron2 , how can i use the centermask2 in pure pytorch network defines and weights ? HOT 2
- About backbone pretrained models
- RuntimeError: nvrtc: error: invalid value for --gpu-architecture (-arch) HOT 1
- No such file or directory: 'datasets/coco/panoptic_stuff_train2017'
- Inference on random images using pre-trained models with demo.py does not produce meaningful results HOT 2
- What is the default input size for Centermask-Lite?
- how to test single image
- The difficulty in handling overlapping bounding boxes
- KeyError: "No object named 'build_fcos_vovnet_fpn_backbone' found in 'BACKBONE' registry!" HOT 9
- loss mask has remained unchanged during the training process. Why is this?
- how to use centermask-lite demo?
- May be error in MaskIOU module
- Imagenet pretrain 모델로 연락드립니다.
- on the iou loss between pred_boxes and gt_boxes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from centermask2.