Coder Social home page Coder Social logo

soumyaiitkgp / custom_maskrcnn Goto Github PK

View Code? Open in Web Editor NEW
68.0 4.0 48.0 78.84 MB

Custom Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow

License: Other

Python 100.00%
maskrcnn computer-vision deep-learning implementation-of-research-paper

custom_maskrcnn's People

Contributors

bill2239 avatar borda avatar cclauss avatar concerttttt avatar coreyhu avatar cpruce avatar jmtatsch avatar jningwei avatar keineahnung2345 avatar llltttppp avatar manasbedmutha98 avatar marluca avatar maxfrei750 avatar moorage avatar mowoe avatar np-csu avatar philferriere avatar ps48 avatar robaleman avatar rymalia avatar skt7 avatar soumyaiitkgp avatar stevenhickson avatar veemon avatar viredery avatar waleedka avatar xelmirage avatar yanfengliu avatar yqnlp avatar ziyigogogo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

custom_maskrcnn's Issues

How to calculate TP , TN, FP and FN ?

@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?

Applying the maskRCNN on custom dataset

Premise:

  • The project that I am dealing is weed detection in the environment of carrot saplings.
  • The dataset for our project consists of image files and json file for the category_ids, image file ids etc.,
  • Results -- predicting the maximum weeds so they can be rid of
    -- visualize by masking the saplings

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...
custom_rncnn_err2

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.

Issue while trying to train model

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.

custom demo.ipynd needs an update

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)

Building the model for the first time with custom dataset

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

Detection scores is always >0.9 even for wrong detections

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.

Issue while loading weights in the inspect_custom_model.ipynb

When I have to load the newly generated custom model, I get the str doesn't have a decode attribute error

`

Or, load the last model you trained

weights_path = model.find_last()

Load weights

print("Loading weights ", weights_path)
model.load_weights(weights_path, by_name=True)
`
err_1
err_2

Please advice.

No module named 'coco'

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

Only display one class

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.