soumyaiitkgp / custom_maskrcnn Goto Github PK
View Code? Open in Web Editor NEWCustom Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
License: Other
Custom Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
License: Other
@soumyaiitkgp I am using my own dataset which consists of 1235 images in total. I have divided 864 images into a training set and 371 images in the test set. After the training process is done, I am trying to make predictions on each image in my test set. I know that there is a "compute_ap" function which returns the mAp value after sending "gt_bbox, gt_class_id, gt_mask, r["rois"], r["class_ids"], r["scores"], r['masks']" as parameters. But I want to know the values of TP, TN, FP, and FN of the entire test set? Can you please help me in finding these values? Is there any predefined function available in the model which returns these values?
Premise:
Followed Soumi's Read the guide and trying to apply the class_id, issue is that the annotations that I have extracted from my project's dataset has no class_id. Sample of annotations.json is as follows
"annotations": [ { "area": 13026.0, "bbox": [ 1773.0023578923756, 1194.7026978561953, 222.80523106412875, 194.66877198054863 ], "category_id": 1, "id": 6155, "image_id": 362, "iscrowd": 0, "segmentation": [ [ 1981.767578125,
So at the most I can add only category_id
-Next in your custom.py, you have a file called (Not sure where that file is, although you are referring it as containing annotations... ?) not sure how to reconcile that...
I am not sure how to apply your code for weed detection, even though you just mention about being able to apply, in your readme.
Please respond.
So I have followed the Medium article and am trying to train the model on a custom dataset of floorplans. After working around some issues I found I am finally ready to train.
However, now I run into a new problem which I can not seem to fix myself. When trying to train on a custom dataset, I get the following error:
Traceback (most recent call last): File "custom.py", line 391, in <module> train(model) File "custom.py", line 222, in train layers='heads') File "C:\...\Custom_MaskRCNN-master\mrcnn\model.py", line 2356, in train self.compile(learning_rate, self.config.LEARNING_MOMENTUM) File "C:\...\Custom_MaskRCNN-master\mrcnn\model.py", line 2201, in compile self.keras_model.add_metric(loss, name) AttributeError: 'Model' object has no attribute 'add_metric'
This comes right after the model should start training, stating that it is starting at epoch 0.
We are kind of at a loss, as we have been struggling to use this model for a couple of hours now.
If anybody knows a solution that would be very much appreciated.
The current demo.ipynb only supports coco model/weights. Need to update the notebook to use custom config, and to use custom model weights.
TL;DR:
These needs an update:
# Import COCO config
sys.path.append(os.path.join(ROOT_DIR, "samples/coco/")) # To find local version
import coco
replace with
# Import Custom config
sys.path.append(os.path.join(ROOT_DIR, "samples/custom/")) # To find local version
import custom
# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")
# Download COCO trained weights from Releases if needed
if not os.path.exists(COCO_MODEL_PATH):
utils.download_trained_weights(COCO_MODEL_PATH)
replace with
# Local path to trained weights file
CUSTOM_MODEL_PATH = os.path.join(MODEL_DIR, "mask_rcnn_custom.h5")
class InferenceConfig(coco.CocoConfig):
# Set batch size to 1 since we'll be running inference on
# one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU
GPU_COUNT = 1
IMAGES_PER_GPU = 1
replace with
class InferenceConfig(custom.CustomConfig):
# Set batch size to 1 since we'll be running inference on
# one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU
GPU_COUNT = 1
IMAGES_PER_GPU = 1
# Load weights trained on MS-COCO
model.load_weights(COCO_MODEL_PATH, by_name=True)
replace with
# Load weights trained on custom
model.load_weights(CUSTOM_MODEL_PATH, by_name=True)
Steps followed as per your link https://medium.com/analytics-vidhya/a-simple-guide-to-maskrcnn-custom-dataset-implementation-27f7eab381f2:
Step 1 - cloned your repo
Step 2: Prepare the data (90:10)
Step 3: Prepare the model.- for this I made the necessary changes to add my custom class (in my case just one) - Running under GPU compute instance in Azure ML workspace
-- line 91 and 140
-- and also in the CustomConfig class line 71 in my case NUM_CLASSES = 1 + 1
ran the script
python custom.py train --dataset="Users/pankaja_us/Custom_MaskRCNN/samples/custom/dataset/train" --weights=coco
getting the following error -->
2020-12-18 21:52:27.922509: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1241] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10812 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0001:00:00.0, compute capability: 3.7)
Traceback (most recent call last):
File "custom.py", line 375, in
model_dir=args.logs)
File "/mnt/resource/batch/tasks/shared/LS_root/mounts/clusters/pankaja-gpu1/code/users/pankaja_us/Custom_MaskRCNN/mrcnn/model.py", line 1837, in init
self.keras_model = self.build(mode=mode, config=config)
File "/mnt/resource/batch/tasks/shared/LS_root/mounts/clusters/pankaja-gpu1/code/users/pankaja_us/Custom_MaskRCNN/mrcnn/model.py", line 1990, in build
target_rois, input_gt_class_ids, gt_boxes, input_gt_masks])
File "/anaconda/envs/azureml_py36/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "/anaconda/envs/azureml_py36/lib/python3.6/site-packages/keras/engine/base_layer.py", line 489, in call
output = self.call(inputs, **kwargs)
File "/mnt/resource/batch/tasks/shared/LS_root/mounts/clusters/pankaja-gpu1/code/users/pankaja_us/Custom_MaskRCNN/mrcnn/model.py", line 664, in call
self.config.IMAGES_PER_GPU, names=names)
File "/mnt/resource/batch/tasks/shared/LS_root/mounts/clusters/pankaja-gpu1/code/users/pankaja_us/Custom_MaskRCNN/mrcnn/utils.py", line 820, in batch_slice
output_slice = graph_fn(*inputs_slice)
File "/mnt/resource/batch/tasks/shared/LS_root/mounts/clusters/pankaja-gpu1/code/users/pankaja_us/Custom_MaskRCNN/mrcnn/model.py", line 663, in
w, x, y, z, self.config),
File "/mnt/resource/batch/tasks/shared/LS_root/mounts/clusters/pankaja-gpu1/code/users/pankaja_us/Custom_MaskRCNN/mrcnn/model.py", line 553, in detection_targets_graph
positive_indices = tf.random_shuffle(positive_indices)[:positive_count]
AttributeError: module 'tensorflow' has no attribute 'random_shuffle'
azureuser@pankaja-gpu1:/mnt/resource/batch/tasks/shared/LS_root/mounts/clusters/pankaja-gpu1/code/users/pankaja_us/Custom_MaskRCNN/samples/custom$
Please advise. What other changes do I need to make?
TIA
Pankaja
Hi Soumya,
This is not related to usage maskrcnn from your repo.
I am using matterport implementation of maskrcnn and train my custom data. While detection the scores for each instance in images is always greater than 0.9 even when the detection is incorrect. Say the instance is ball and is being detected as knife but the detection score is 0.97. Can you help me with the pausible reasons or where should i look into.
I have tried looking into the model.py and util and config.
Hello Soumya,
I have been trying to run your MaskRCNN code for an object detection project and have been running into this error. I believe that the script is not able to download the coco weights but am not sure how to fix it.
Thanks,
Saurav
Nice project.I tried to run 'demo.ipynb', but it gave me an error!
sys.path.append(os.path.join(ROOT_DIR, "samples\\custom\\")) # To find local version
import coco
Using TensorFlow backend.
ModuleNotFoundError Traceback (most recent call last)
in ()
19 #sys.path.append(C:\ProgramData\Anaconda3\Lib\site-packages\pycocotools)
20 sys.path.append(os.path.join(ROOT_DIR, "samples\custom\")) # To find local version
---> 21 import coco
22 #from samples.coco import coco
23 get_ipython().run_line_magic('matplotlib', 'inline')
ModuleNotFoundError: No module named 'coco'
I tried using my local version and it didn't work.
sys.path.append(C:\ProgramData\Anaconda3\Lib\site-packages\pycocotools)
python :3.6.5
tensorflow :1.15.0
pycocotools:2.0.2
keras:2.0.8
I can only display one class, I think there may be a problem with custom.py.
num_ids=[]
#Add the classes according to the requirement
for n in custom:
try:
if n['label']=='object1':
num_ids.append(1)
elif n['label']=='object2':
num_ids.append(2)
except:
pass
In custom.py ,num_ids is not being used.I read another article.https://github.com/matterport/Mask_RCNN/issues/372#issuecomment-377010489
Maybe this code should be changed.
self.add_image( "custom", image_id=a['filename'], # use file name as a unique image id path=image_path, width=width, height=height, polygons=polygons)
# Return mask, and array of class IDs of each instance. Since we have # one class ID only, we return an array of 1s return mask.astype(np.bool), np.ones([mask.shape[-1]], dtype=np.int32)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.