I already tried this version but google colab by default take 3.8.20 not 3.8.0 And then I process this tenserflow and keras version but still I am getting of other requirement version problem which was not working in this version --can u share your env setup
Mam your videos are very on-point, easy to understand and implement. Your previous videos helped me as well just like how this video helped me now. You are doing a good work. Thankyou.
Hi Mam, I have completed all steps what u have taught in your tutorial. Actually i want to mask liver from CT image. So I have created two classes for Liver and Spleen using CT image. ( The python is installed in C drive anf my project is stored in the path C:\New_project_mask_rcnn) Finally i got the following in the output window.......... objects: ['liver'] numids [1] objects: ['spleen'] numids [2] objects: ['liver'] numids [1] objects: ['liver'] numids [1] Traceback (most recent call last): File "C:\New_project_mask_rcnn\custom.py", line 167, in dataset_val.load_custom(r'C:\New_project_mask_rcnn\Dataset',"val") File "C:\New_project_mask_rcnn\custom.py", line 103, in load_custom image = skimage.io.imread(image_path) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\skimage\io\_io.py", line 48, in imread img = call_plugin('imread', fname, plugin=plugin, **plugin_args) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\skimage\io\manage_plugins.py", line 209, in call_plugin return func(*args, **kwargs) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread return np.asarray(imageio_imread(*args, **kwargs)) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core\functions.py", line 159, in imread with imopen(uri, "ri", plugin=format) as file: File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core\imopen.py", line 161, in imopen request = Request(uri, io_mode, format_hint=format_hint) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core equest.py", line 248, in __init__ self._parse_uri(uri) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core equest.py", line 388, in _parse_uri raise FileNotFoundError("No such file: '%s'" % fn) FileNotFoundError: No such file: 'C:\New_project_mask_rcnn\Dataset\val\image1.jpg' ------------------------------------------------------------------------------ In the valitation folder named "val" The image1 is a picture stored in Training folder named as "train". i donot have stored any image with name image1. ------------------------------------------------------------------------------------ How do solve this issue? Please guide me mam...
good evening mam..your teaching is more excellent mam..kindly upload this implementation of mask rcnn in colab platform mam..so that it can very much useful for our students mam...thank you so much for your excellent effort mam..
Hi, Follow this process to run the code in colab. Just paste this entire code folder in your google drive. Then the code which I wrote in custom.py file, paste it in the colab and run. Make sure to select the GPU from notebook settings. Also, make sure to change the paths in custom.py file code when you paste it in colab. You can ask me queries if you face any problems while running on colab.
The explanation from the previous video and the implementation in this video is too good ❤️. Keep up the good work mam ❤️Try to make videos on Big Data too 😊🙏
i might need to implement mask r cnn for 3D image stacks, havent found any good implementations yet, was wondering how hard it would be to achieve this
This is a great video illustrating the MRCNN implementation. Currently, im working on a project and im trying to visualize the top masks of random images in my training dataset and the top masks are showing distortion. I went back a few steps to print out the masks in from the for loop of image_ids and i got a bunch of arrays of false as output. Im not sure why im getting false as output.
mam how one can get the train data as images rather than json file. and if I want to add some new classes example glass then how it is possible plz make video on that.
Thanks Mam for your valuable guidance. I have few queries: 1. I have implemented it as per your steps but test performance is very poor. What should be the training strategy for improved performance? 2. Min. Epochs required on COlab?. How can I run on video?
@@CodeWithAarohi Thank you. I've been getting an error coming from the load_mask function. Please how do I solve this? IndexError: index 1280 is out of bounds for axis 1 with size 1280
Hi Aarohi, that's a very good explanation, but how do you count the class when you want to detect a car and a number plate? Should one call car as class 1 and number plate as class 2?
The number of images required to train an accurate object detection model for grapes can vary depending on several factors such as the complexity of the grape images, the number of classes to be detected (e.g., green grapes, red grapes), the quality of the images, and the desired level of accuracy. In general, a good rule of thumb is to have at least 400-500 hundred training images
In Mask R-CNN, it's generally a good practice to resize your input data to a consistent size before performing annotation and training. This helps ensure that the data is processed uniformly and simplifies the training process.
Hi, Madam. That is very informative knowledge to learn step by step using mask rcnn. I wonder, how can i continue or extend the learning epoch. I have following your step but making some adjustment with my own dataset and about 50 epochs. but my result is not fulfill, so i want to extend the training but does not want to start over because my training will take about 6-7 hours. so can you guide me? thanks.
I am getting the following error: File "custom.py", line 77, in load_custom annotations = [a for a in annotations if a['regions']] File "custom.py", line 77, in annotations = [a for a in annotations if a['regions']] TypeError: list indices must be integers or slices, not str
@@eyeris5812 yes you need to change it to str.. where it accepts as int… it’s mid night in my region and Saturday too.. i will reply in detail on monday
Hello ma'am, You have explained really well but when we do data augmentation for example flip,or rotate than our original annotations position will also be changed? For example if I annotate a building which is on right side than if we do augmentation of flip than the building will be augmented on left side does the annotation also change its position?how does it work? Please explain
@@CodeWithAarohi yes this I know but what I am actually asking is what about the annotation i.e the mask?When for example an image is fliped, will the ground truth polygon from the json file i.e the cordinates for the particular instance in the image also fliped? Because if the image is fliped, then the instance is in another position, right?how to do this? I would appreciate your answer.
Mask R-CNN does not automatically handle updating the annotations when applying transformations to the images. We have to do it manually. Detectron2 or TensorFlow's Object Detection API, provide functionalities for data augmentation and automatically handle updating the annotations when applying transformations to the images. Below is an example of a custom Python code that uses the popular library imgaug for image augmentation and creates new annotations for the corresponding augmented images in the context of Mask R-CNN. pip install imgaug import imgaug.augmenters as iaa import numpy as np import cv2 # Function to apply horizontal flipping to the image and annotations def flip_image_and_annotations(image, bounding_boxes, segmentation_masks): # Create an augmenter for horizontal flipping flipper = iaa.Fliplr(1.0) # Apply the flip augmentation to the image flipped_image = flipper.augment_image(image) # Get image width for calculating new bounding box coordinates image_width = image.shape[1] # Flip bounding boxes flipped_bounding_boxes = [] for box in bounding_boxes: x_min, y_min, x_max, y_max = box x_min_flipped, x_max_flipped = image_width - x_max, image_width - x_min flipped_bounding_boxes.append([x_min_flipped, y_min, x_max_flipped, y_max]) # Flip segmentation masks flipped_segmentation_masks = [] for mask in segmentation_masks: # Assuming segmentation masks are binary (0 for background, 1 for object) flipped_mask = np.fliplr(mask) flipped_segmentation_masks.append(flipped_mask) return flipped_image, flipped_bounding_boxes, flipped_segmentation_masks # Example usage if __name__ == "__main__": # Load the original image, bounding boxes, and segmentation masks original_image = cv2.imread("path_to_original_image.jpg") original_bounding_boxes = [[50, 100, 150, 200]] # Example format: [x_min, y_min, x_max, y_max] original_segmentation_masks = [np.ones((original_image.shape[0], original_image.shape[1]))] # Apply augmentation and get augmented image, bounding boxes, and masks augmented_image, augmented_bounding_boxes, augmented_segmentation_masks = flip_image_and_annotations( original_image, original_bounding_boxes, original_segmentation_masks ) # Save the augmented image and annotations or use them for training Mask R-CNN cv2.imwrite("path_to_save_augmented_image.jpg", augmented_image) print("Augmented Bounding Boxes:", augmented_bounding_boxes) print("Augmented Segmentation Masks:", augmented_segmentation_masks) In this example, we used imgaug to implement horizontal flipping. You can similarly add other augmentation techniques or combine multiple augmenters from the imgaug library to perform a wide range of data augmentation.
Thanks a lot ma'am for your guidance. Ma'am in your test_truck_car_model.ipynb notebook.... Is the Confusion matrix code In the last cell working correctly?
on the mean average precision i get this error: AttributeError: module 'utils' has no attribute 'gt_pred_lists' even though the utils has this attribute, i don't get it!
First of all, thanks for an amazing tutorial. Secondly, when I run the file, I get this error: FileNotFoundError: No such file: 'C:\Users\Saad Salman\Desktop\Mask-RCNN\Dataset\val\angry.8affb600-fe31-11ec-bcdd-b46bfc8af0c1.jpg'. However, this file is in the training folder. I dont know why is it searching for it in the val folder
@@AnumFatima427 I pasted a comment referring to a blog that uses Mask RCNN, which was deleted, I don't know why. Using the code from that I solved this issue in my implementation.
I found a solution from comments and it worked for me, 1. Place Json file in val and train folder with "same name" 2. Give json file path like this: annotations=json.load(open(os.path.join(dataset_dir, 'Json file name')))
Why did you copy the same datasets in both folders; train and val? Is this a correct approach? Could you give some insights? In my opinion, we should split the datasets into train and validation. Or?
No, it is not mandatory to use the VIA tool for annotating images if you are annotating for Mask R-CNN. There are several other tools available that can be used for image annotation, such as labelImg, RectLabel, and COCO Annotator
Adjust the batch size. Smaller batch sizes may lead to faster training per epoch. And you can also adjust the learning rate. A learning rate that is too high may cause the model to converge slowly or not at all, while a learning rate that is too low may slow down convergence. Experiment with different learning rates to find an optimal value.
@@CodeWithAarohi After running on Tensorflow 1.14 and keras 2.2.5, I am still experiencing another error AttributrError: 'Node' object has no attribute 'output_masks'
@@CodeWithAarohi Do you prefere any library to use ? I used keras2onnx but i get some errors and also in library's github it says "However some models with a lot of custom operations need custom conversion, the following are some examples, like YOLOv3, and Mask RCNN." I dont know how to accomplish custom conversion can you suggest any resources ?
Hi Aarohi maam, I have two classes for which I followed your tutorials on RCNN. I am getting an error: raise FileNotFoundError("No such file: '%s'" % fn) FileNotFoundError: No such file: '/Users/r/Desktop/mrcnn/dataset/val/checkbox_on_1.jpg' In my dataset, I have 66 training data (for 2 classes) and 09 validation data. At the time of execution, the program gives the error. The file, program is looking for, is in the training folder. But it searches for that particular file in the validation folder as well. "checkbox_on_1.jpg' file is only in the train folder, not sure why it is also asking for the same file in tge val folder? How can I solve this?
Hello I had the same problem , just change your subset = "train" and comment these lines # Train or validation dataset? #assert subset in ["train", "val"] dataset_dir = os.path.join(dataset_dir, "train")
Hi Aarohi, many thanks for the explanation..one thing--> why we need to choose latest epoch? may be your 2nd last epoch or some epoch in middle could give you min loss value compare to all others right??
HI Aarohi, I love learning from your videos they are very informative. I am applying Mask-RCNN. on custom dataset but I want to use Resnet50 what changes do I need to perform
@@CodeWithAarohi hello, I want to use resnet50 instead of resnet101 as the backbone. What changes needs to be done for that. I would be really obliged if you could explain this backbone change part as well
@@CodeWithAarohi I tried changing the backbone from resnet101 to resnet50 and working on maskRCNN as segmentation model, but no luck. Any suggestions for how to implement?
Hi Arohi ji I want to ask one thing: If we are annotating images using vgg annotator.It seems applicable for train set images but why to annotate validation set using vgg annotator?It should be now a task of mask rcnn to identify objects and apply mask
Hello...Training set is used to train the model. We annotate val data because Validation data is used for regularization. It also helps in avoiding the problem of overfitting. It basically estimates the prediction error. Test data is used to evaluate model.
Hello Mam, Thanks for your good explanation and detailed video. One doubt here : is it necessary that the number of images in the train and val folders be same ? Or in the JSON file? As the "annotations" variable is calculating nubmer of indexes from the train.json file. And i am also getting the error for the same saying that , val.json cannot find some files when number of images are different in train and val folder. However when i careful checked in your video that is not the case. Thanks.
Number of images can be different in train and val folder. Just have the json file of train and val folder with a same name then use if else condition to read train and val json file
mam the object that i wanted to detect is not there in pretrained models in that case,how would i get cocoweights?.should i necessarily use coco weights? what would i do otherwise? pls guide mam
If the object you want to detect is not in pretrained weights then collect images related to your custom object, annotate those images in the format which Mask R-CNN accepts. Then train your model on that custom dataset. You can train in 2 ways- 1- Train the model from scratch. 2- Use pretrained model and then fine tune it with you custom dataset.
Thankyou mam for your concern to take time and reply.one more doubt mam,can i annotate objects after zooming it,,will it cause any performance variation when i use that model in online..can you please tag video on training a model from scratch using mask rcnn.
Thanks great work How did you create a separate environment? And my PC doesn’t have a dedicated GPU how can i run the training this way? How did you launch the test model file on jupyter notebook? I downloaded the file but I can’t open it! Kindly help!
Thanks for the share, but I have a remark On this lines : "assert subset in ["train", "val"] dataset_dir = os.path.join(dataset_dir, subset)
annotations1 = json.load(open('D:\\env_with_tensorflow1.14\\all_maskrcnn\\maskrcnn_truck_car\\Dataset\\train\\train_json.json'))" The dataset dir end with '\train' or '\val' but on your 'annotations1' there is only the path to 'train' subset. The problem is that when the subset will be 'val' the image_path = os.path.join(dataset_dir, a['filename']) on line 95 will be incorrect because a['filename'] access to the file names of the train json image and not the val image. So if the filename is image_train.jpg the path would be ''...\\Dataset\\val\\image_train.jpg" but on the val_json there is not train image but only "v1","v2" so there will be an error. So its necessary to change the path of the annotations1 according to the subset.
Hi, You have given the path to json file of annotation info of training data but json file for validation data is not given. I faced this error and passed separate json files for train and validation data. Now it starts to train Epoch 1 but I cannot see CPU or GPU consumption. Please help.
Hi Aarohi, Thank you very much for this very useful tuto. Actually, I am facing an issue, the bounding boxes are too small, and I do not know how to extend their limits? If you have any idea... Thank you! PL
Ma'am my training has run successfully but during testing when we take random image the box is not appearing and it is appearing in the whole image so ma'am can you suggest me what I need to do now
I need more details like how many classes you are working upon? How many images per class you have etc. Mail me all your project details at aarohisisngla1987@gmail.com
i am having python 3.8.0 but many errors are coming due to different version compatiblity , can you give what all versions are required for each library
Hello Aarohi (perhaps this is some basic, sorry.) . I'm following this and other tutorials and I would appreciate an orientation on how to create the environment for running this code (as the one you use from min 20:00 onwards). I'm searching an (*.yml) file with the specs on the repo... but in can't find it. thanks in advance!
Hey were you able to get the log files? As per reply the log files is generated after training but in the code we are using log before training itself, so does that work ?
@@shreyasgupta5514 I have created the log folder before because my coco dataset weights are there. But if you are not putting your coco dataset weights in that log folder then this folder will get created when training starts and epoch wise it will store the trained weights
hi, Wonderful tutorial, I am getting an error ImportError: cannot import name 'AnonymousIteratorV3' from 'tensorflow.python.ops.gen_dataset_ops' how torectify it?'
Hello Aarohi, in other implementations to calculate the mAP I have seen that before applying the model.detect function on the image they apply the functions of mold_image from modellib and expand_dims from numpy, to convert the pixel values and to convert the image into only one sample. Using your method I get a higher value of mAP than with the other implementations. Are those steps that I am telling you necessary?
I am not sure about the other methods which you are talking about as I worked with this method only. And I think the approach we are using to get the mAP is correct
Hi Ma'am, can you provide us the version of tensorflow, keras and python you used for successfully running this code? I did the exact same thing as you mentioned in this video but I am having a error called "ValueError: Tried to covert 'shape' to a tensor and failed. Error: None values not supported."
Hi Aarohi, I have a question to ask:how to lebeling ,detect and classify multiclass in one image using MaskRCNN ?hint,one image has multiclass and also one class has the more than one object so how to leveling them using VIA or how to perpare json file ?
@@CodeWithAarohi ok thanks madam,but ,how to lebeling more than one object in one class?for example object1,object2 ,object3,....... etc all are lebeling in one class and also class2,class3,.....etc
Hello madam, please confirm whether the data in train and validation while creating annotation using VGG annotation should be same or different because i am getting very low detection precision here is the output for detecting KNEE MRI BONE Processing 1 images image shape: (1024, 1024, 3) min: 0.00000 max: 64280.00000 int32 molded_images shape: (1, 1024, 1024, 3) min: -123.70000 max: 64176.10000 float64 image_metas shape: (1, 16) min: 0.00000 max: 1024.00000 int64 anchors shape: (1, 261888, 4) min: -0.35390 max: 1.29134 float32 the actual length of the ground truth vect is : 3 the actual length of the predicted vect is : 3 Average precision of this image : 0.0 The actual mean average precision for the whole images 0.0
Hi Aarohi,i am unable to download the class-descriptions-boxable.csv file, train-annotations-bbox.csv file from the command Can u please help me to fix it?
This code is tested on Python 3.8.0, tensorflow 2.4.0, keras 2.3.1 and h5py 2.10.0
I already tried this version but google colab by default take 3.8.20 not 3.8.0
And then I process this tenserflow and keras version but still I am getting of other requirement version problem which was not working in this version --can u share your env setup
@@TechTravel_with_MAC
did you get solution, please share it in comment box
Thanks!
Welcome :)
I am in USA and working on imaging. I appreciate you highly. You did a great job. Excellent
Thank you so much 😀
YOU ARE THE BEST WOMAN IN THE WORLD!)))
Mam your videos are very on-point, easy to understand and implement. Your previous videos helped me as well just like how this video helped me now. You are doing a good work. Thankyou.
Glad to hear that 😊
very neat, clear, and simple explanation.. Keep it up madam
Thank you so much 🙂
A very clear explanation mam.. Thanks a lot...Live long ....
Glad my video is helpful!
Amazing explaination. Super helpful; thank you!
Glad it was helpful!
Wow. Very nicely explained
Glad you liked it
thank you so much you dont how much you are helping me right now God bless you
Glad to hear that!
Hi Mam, I have completed all steps what u have taught in your tutorial. Actually i want to mask liver from CT image. So I have created two classes for Liver and Spleen using CT image.
( The python is installed in C drive anf my project is stored in the path C:\New_project_mask_rcnn)
Finally i got the following in the output window..........
objects: ['liver']
numids [1]
objects: ['spleen']
numids [2]
objects: ['liver']
numids [1]
objects: ['liver']
numids [1]
Traceback (most recent call last):
File "C:\New_project_mask_rcnn\custom.py", line 167, in
dataset_val.load_custom(r'C:\New_project_mask_rcnn\Dataset',"val")
File "C:\New_project_mask_rcnn\custom.py", line 103, in load_custom
image = skimage.io.imread(image_path)
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\skimage\io\_io.py", line 48, in imread
img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\skimage\io\manage_plugins.py", line 209, in call_plugin
return func(*args, **kwargs)
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread
return np.asarray(imageio_imread(*args, **kwargs))
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core\functions.py", line 159, in imread
with imopen(uri, "ri", plugin=format) as file:
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core\imopen.py", line 161, in imopen
request = Request(uri, io_mode, format_hint=format_hint)
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core
equest.py", line 248, in __init__
self._parse_uri(uri)
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core
equest.py", line 388, in _parse_uri
raise FileNotFoundError("No such file: '%s'" % fn)
FileNotFoundError: No such file: 'C:\New_project_mask_rcnn\Dataset\val\image1.jpg'
------------------------------------------------------------------------------
In the valitation folder named "val"
The image1 is a picture stored in Training folder named as "train".
i donot have stored any image with name image1.
------------------------------------------------------------------------------------
How do solve this issue? Please guide me mam...
i also got same issue. please reply how to solve the issue.
Hi Aarohi, I have a question to ask: how can the total IOU be calculated for each single class to be predicted? Thanks for your deep learning videos.
good evening mam..your teaching is more excellent mam..kindly upload this implementation of mask rcnn in colab platform mam..so that it can very much useful for our students mam...thank you so much for your excellent effort mam..
Hi, Follow this process to run the code in colab. Just paste this entire code folder in your google drive. Then the code which I wrote in custom.py file, paste it in the colab and run. Make sure to select the GPU from notebook settings. Also, make sure to change the paths in custom.py file code when you paste it in colab. You can ask me queries if you face any problems while running on colab.
The explanation from the previous video and the implementation in this video is too good ❤️. Keep up the good work mam ❤️Try to make videos on Big Data too 😊🙏
Thank you, I will make videos on Big data
hai ma'am i have error in may program after training, the error like this
UnboundLocalError: local variable 'image_id' referenced before assignment
Great job, Ma'am!!
Thank you! 😊
i might need to implement mask r cnn for 3D image stacks, havent found any good implementations yet, was wondering how hard it would be to achieve this
You're amazing 👏, thank you!
Happy to help!
Ma'am can you tell us where we need to see accuracy in the training
Thank you so much❤ This video helps me a lot to complete my research.
Glad it was helpful!
indebted to you maam .
Glad my video is helpful :)
how to display matrix, and accuracy?
i want to train Mask-RCNN on python 3.9.7 ..please can you share the requirements.txt?
This is a great video illustrating the MRCNN implementation. Currently, im working on a project and im trying to visualize the top masks of random images in my training dataset and the top masks are showing distortion. I went back a few steps to print out the masks in from the for loop of image_ids and i got a bunch of arrays of false as output. Im not sure why im getting false as output.
mam how one can get the train data as images rather than json file. and if I want to add some new classes example glass then how it is possible plz make video on that.
for setting enviornment can you provide specifications you have used.
Thank you.
python 3.6.8, tensorflow 1.14.0, keras 2.3.0, h5py version 2.10.0
Can you please mention the versions u use?
Thanks Mam for your valuable guidance. I have few queries: 1. I have implemented it as per your steps but test performance is very poor. What should be the training strategy for improved performance? 2. Min. Epochs required on COlab?. How can I run on video?
Mam in which file i have to perform preprocessing techniques mam Please reply mam??
please make the video on the HAM10000 dataset for skin lesion that how to import this dataset and use it.
Amazing sis
Thanks 😊
Thank you mam.. But if I keep different images then during inference mode it shows run time error about as image not found
It works fine only if there are same images in train and Val folder madam
Thanks for the video tutorial! However, you didn't put the link to the pre-trained weights. How can I get it?
github.com/matterport/Mask_RCNN/releases/download/v2.0/mask_rcnn_coco.h5
@@CodeWithAarohi Thank you. I've been getting an error coming from the load_mask function. Please how do I solve this?
IndexError: index 1280 is out of bounds for axis 1 with size 1280
Hi Aarohi, that's a very good explanation, but how do you count the class when you want to detect a car and a number plate? Should one call car as class 1 and number plate as class 2?
mam what if i have different json file from each images? how do i train a mask rcnn
How can we show this on like Vscode using python?
if you get long data set how to validation
Mam !!! how many images should be trained to get an accurate object detection output to detect grapes?
The number of images required to train an accurate object detection model for grapes can vary depending on several factors such as the complexity of the grape images, the number of classes to be detected (e.g., green grapes, red grapes), the quality of the images, and the desired level of accuracy.
In general, a good rule of thumb is to have at least 400-500 hundred training images
Images must have the same size? thanks madam
In Mask R-CNN, it's generally a good practice to resize your input data to a consistent size before performing annotation and training. This helps ensure that the data is processed uniformly and simplifies the training process.
Thanks a lot for your answer @@CodeWithAarohi
Hi, Madam. That is very informative knowledge to learn step by step using mask rcnn. I wonder, how can i continue or extend the learning epoch. I have following your step but making some adjustment with my own dataset and about 50 epochs. but my result is not fulfill, so i want to extend the training but does not want to start over because my training will take about 6-7 hours. so can you guide me? thanks.
Hi mam, I want to know how can we compute the feature map of mask rcnn? Any code or help you can give.thanks
Arohi ji, thank yiu for the explaination...
How do we proceed if we already have the masked images as our target ?
Then start by running custom.py file
what are version used for tensorflow and keras
This code is tested on Python 3.8.0, tensorflow 2.4.0, keras 2.3.1 and h5py 2.10.0
It is showing warning: you are using default load mask(),may be you need to define your own one...repeatedly..plz help
I am getting the following error:
File "custom.py", line 77, in load_custom
annotations = [a for a in annotations if a['regions']]
File "custom.py", line 77, in
annotations = [a for a in annotations if a['regions']]
TypeError: list indices must be integers or slices, not str
same error, u got any solution?
@@THEULTIMATEPRASHANT have you found a solution yet?
@@eyeris5812 yes you need to change it to str.. where it accepts as int… it’s mid night in my region and Saturday too.. i will reply in detail on monday
@@THEULTIMATEPRASHANT Bhai, we might be from the same region, thank you though!
@@THEULTIMATEPRASHANT how to correct this? Plz help if you know how, thank you so much
Hello ma'am,
You have explained really well but when we do data augmentation for example flip,or rotate than our original annotations position will also be changed? For example if I annotate a building which is on right side than if we do augmentation of flip than the building will be augmented on left side does the annotation also change its position?how does it work? Please explain
You can do this : # model.train(dataset_train, dataset_val,
# learning_rate=config.LEARNING_RATE,
# epochs=600,
# layers='heads', #layers='all',
# augmentation = imgaug.augmenters.Sequential([
# imgaug.augmenters.Fliplr(1),
# imgaug.augmenters.Flipud(1),
# imgaug.augmenters.Affine(rotate=(-45, 45)),
# imgaug.augmenters.Affine(rotate=(-90, 90)),
# imgaug.augmenters.Affine(scale=(0.5, 1.5)),
# imgaug.augmenters.Crop(px=(0, 10)),
# imgaug.augmenters.Grayscale(alpha=(0.0, 1.0)),
# imgaug.augmenters.AddToHueAndSaturation((-20, 20)), # change hue and saturation
# imgaug.augmenters.Add((-10, 10), per_channel=0.5), # change brightness of images (by -10 to 10 of original value)
# imgaug.augmenters.Invert(0.05, per_channel=True), # invert color channels
# imgaug.augmenters.Sharpen(alpha=(0, 1.0), lightness=(0.75, 1.5)), # sharpen images
# ]
# ))
@@CodeWithAarohi yes this I know but what I am actually asking is what about the annotation i.e the mask?When for example an image is fliped, will the ground truth polygon from the json file i.e the cordinates for the particular instance in the image also fliped? Because if the image is fliped, then the instance is in another position, right?how to do this? I would appreciate your answer.
Mask R-CNN does not automatically handle updating the annotations when applying transformations to the images. We have to do it manually.
Detectron2 or TensorFlow's Object Detection API, provide functionalities for data augmentation and automatically handle updating the annotations when applying transformations to the images.
Below is an example of a custom Python code that uses the popular library imgaug for image augmentation and creates new annotations for the corresponding augmented images in the context of Mask R-CNN.
pip install imgaug
import imgaug.augmenters as iaa
import numpy as np
import cv2
# Function to apply horizontal flipping to the image and annotations
def flip_image_and_annotations(image, bounding_boxes, segmentation_masks):
# Create an augmenter for horizontal flipping
flipper = iaa.Fliplr(1.0)
# Apply the flip augmentation to the image
flipped_image = flipper.augment_image(image)
# Get image width for calculating new bounding box coordinates
image_width = image.shape[1]
# Flip bounding boxes
flipped_bounding_boxes = []
for box in bounding_boxes:
x_min, y_min, x_max, y_max = box
x_min_flipped, x_max_flipped = image_width - x_max, image_width - x_min
flipped_bounding_boxes.append([x_min_flipped, y_min, x_max_flipped, y_max])
# Flip segmentation masks
flipped_segmentation_masks = []
for mask in segmentation_masks:
# Assuming segmentation masks are binary (0 for background, 1 for object)
flipped_mask = np.fliplr(mask)
flipped_segmentation_masks.append(flipped_mask)
return flipped_image, flipped_bounding_boxes, flipped_segmentation_masks
# Example usage
if __name__ == "__main__":
# Load the original image, bounding boxes, and segmentation masks
original_image = cv2.imread("path_to_original_image.jpg")
original_bounding_boxes = [[50, 100, 150, 200]] # Example format: [x_min, y_min, x_max, y_max]
original_segmentation_masks = [np.ones((original_image.shape[0], original_image.shape[1]))]
# Apply augmentation and get augmented image, bounding boxes, and masks
augmented_image, augmented_bounding_boxes, augmented_segmentation_masks = flip_image_and_annotations(
original_image, original_bounding_boxes, original_segmentation_masks
)
# Save the augmented image and annotations or use them for training Mask R-CNN
cv2.imwrite("path_to_save_augmented_image.jpg", augmented_image)
print("Augmented Bounding Boxes:", augmented_bounding_boxes)
print("Augmented Segmentation Masks:", augmented_segmentation_masks)
In this example, we used imgaug to implement horizontal flipping. You can similarly add other augmentation techniques or combine multiple augmenters from the imgaug library to perform a wide range of data augmentation.
Thanks a lot ma'am for your guidance.
Ma'am in your test_truck_car_model.ipynb notebook.... Is the Confusion matrix code In the last cell working correctly?
Yes, it is working
Where is the log folder and files coming from?
Log folder will get created when training starts and you will get your trained models in this folder after every epoch.
mam, I am unable to download the mrcnn folder.
Download that whole repository from github and then copy mrcnn folder from there
@@CodeWithAarohi AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
mam how to resolve this error
on the mean average precision i get this error:
AttributeError: module 'utils' has no attribute 'gt_pred_lists'
even though the utils has this attribute, i don't get it!
First of all, thanks for an amazing tutorial. Secondly, when I run the file, I get this error: FileNotFoundError: No such file: 'C:\Users\Saad Salman\Desktop\Mask-RCNN\Dataset\val\angry.8affb600-fe31-11ec-bcdd-b46bfc8af0c1.jpg'. However, this file is in the training folder. I dont know why is it searching for it in the val folder
I'm facing the same issue
@@AnumFatima427 I pasted a comment referring to a blog that uses Mask RCNN, which was deleted, I don't know why. Using the code from that I solved this issue in my implementation.
@@AnumFatima427 I think I cant post links to blogs here.
I found a solution from comments and it worked for me,
1. Place Json file in val and train folder with "same name"
2. Give json file path like this:
annotations=json.load(open(os.path.join(dataset_dir, 'Json file name')))
hiii mam, My Proggram AttributeError: module 'keras.engine' has no attribute 'Layer' , can you please help me mam?
I use Tensorflow version 2.2
Use Tensorflow 1.14 and keras 2.3.0
Why did you copy the same datasets in both folders; train and val? Is this a correct approach? Could you give some insights? In my opinion, we should split the datasets into train and validation. Or?
You need to put the different set of images in train, val and test.
Does mask rcnn supports binary mask as training in json file?
No
@@CodeWithAarohi how about RLE json annotation format?
I don't have a GPU on my PC, can you share a video that runs on google Colab?
I got data of 30k. what should i do?
Is it mandatory that we have to annotate with VIA
No, it is not mandatory to use the VIA tool for annotating images if you are annotating for Mask R-CNN. There are several other tools available that can be used for image annotation, such as labelImg, RectLabel, and COCO Annotator
the epoch is taking too long any fix for this ??? please reply mam
Adjust the batch size. Smaller batch sizes may lead to faster training per epoch. And you can also adjust the learning rate. A learning rate that is too high may cause the model to converge slowly or not at all, while a learning rate that is too low may slow down convergence. Experiment with different learning rates to find an optimal value.
Mam is there a necessary to do any preprocessing for images if yes in which file I have to do them please reply for this mam
Proprocessing is important.
AttributeError: module 'keras.engine' has no attribute 'Layer' can you please help me mam
Are you running this code on tensorflow 1.14 and keras 2.2.5 ?
@@CodeWithAarohi After running on Tensorflow 1.14 and keras 2.2.5, I am still experiencing another error AttributrError: 'Node' object has no attribute 'output_masks'
@@CodeWithAarohi I am facing the same problem too.
Can we use latest version of tensorflow for this MaskRCNN execution
This code will work with older version but if you want to use it with tensorflow 2 then you need to make changes in the code
Thanks for the video mam. I want to convert my trained model to onnx. Can you help me about that ?
How can I help you?
@@CodeWithAarohi Do you prefere any library to use ? I used keras2onnx but i get some errors and also in library's github it says "However some models with a lot of custom operations need custom conversion, the following are some examples, like YOLOv3, and Mask RCNN." I dont know how to accomplish custom conversion can you suggest any resources ?
Hi Aarohi maam, I have two classes for which I followed your tutorials on RCNN. I am getting an error:
raise FileNotFoundError("No such file: '%s'" % fn)
FileNotFoundError: No such file: '/Users/r/Desktop/mrcnn/dataset/val/checkbox_on_1.jpg'
In my dataset, I have 66 training data (for 2 classes) and 09 validation data. At the time of execution, the program gives the error. The file, program is looking for, is in the training folder. But it searches for that particular file in the validation folder as well. "checkbox_on_1.jpg' file is only in the train folder, not sure why it is also asking for the same file in tge val folder? How can I solve this?
Hello I had the same problem , just change your subset = "train" and comment these lines
# Train or validation dataset?
#assert subset in ["train", "val"]
dataset_dir = os.path.join(dataset_dir, "train")
this happens because the model is taking val folder always so we just set the subset to train
@@shabirahmed6510 how do we resolve this?? I am getting the same error, the images from the train folder is getting checked in the val folder.
Try this
annotations1 = json.load(open(os.path.join(dataset_dir, 'wee_paddy.json')))
keep the name of the json files in the both train and val folders
i had the same issue, anyone solve this? its like annotations for train applied to the val??
Di can you please update a requirement file , which has every installation version required
I have pasted a new requirements.txt file with a name of requirements_new.txt github.com/AarohiSingla/Plant-Disease-Detection-Using-Mask-R-CNN
Thanks a lot Di@@CodeWithAarohi
Welcome@@sameera3017
Hi Aarohi, many thanks for the explanation..one thing--> why we need to choose latest epoch? may be your 2nd last epoch or some epoch in middle could give you min loss value compare to all others right??
Hi, you can choose any weight file as per model performance
Mem one error occurred during execution of train(model) the
AttributeError: SGD' object has no attribut
How to resolve the issue
please provide additional context and code related to the error you are encountering
HI Aarohi, I love learning from your videos they are very informative. I am applying Mask-RCNN. on custom dataset but I want to use Resnet50 what changes do I need to perform
Mask RCNN is a Segmentation model and ResNet is a Image classification model. You can't use ResNet at the place of MaskRCNN.
@@CodeWithAarohi hello, I want to use resnet50 instead of resnet101 as the backbone. What changes needs to be done for that. I would be really obliged if you could explain this backbone change part as well
@@CodeWithAarohi I tried changing the backbone from resnet101 to resnet50 and working on maskRCNN as segmentation model, but no luck. Any suggestions for how to implement?
Hi Arohi ji
I want to ask one thing: If we are annotating images using vgg annotator.It seems applicable for train set images but why to annotate validation set using vgg annotator?It should be now a task of mask rcnn to identify objects and apply mask
Hello...Training set is used to train the model. We annotate val data because Validation data is used for regularization. It also helps in avoiding the problem of overfitting. It basically estimates the prediction error. Test data is used to evaluate model.
Hi Aarohi, please can you tell me what the tensorflow and keras version you used?
Use tensorflow 1.14 and keras 2.2.4
@@CodeWithAarohi thank you
Here you are using .h5 for model file, will the code be same for the .pkl model file? If not please help me to counter this problem.
Hi Arohi, Can you please tell me which Python, tensorflow and keras version you used?
Here, I have used tensorflow 1.x but if you want to work with tensorflow 2.x then check this video: th-cam.com/video/QP9Nl-nw890/w-d-xo.html
Hello Mam,
Thanks for your good explanation and detailed video.
One doubt here : is it necessary that the number of images in the train and val folders be same ? Or in the JSON file?
As the "annotations" variable is calculating nubmer of indexes from the train.json file. And i am also getting the error for the same saying that , val.json cannot find some files when number of images are different in train and val folder. However when i careful checked in your video that is not the case. Thanks.
Number of images can be different in train and val folder. Just have the json file of train and val folder with a same name then use if else condition to read train and val json file
My Epoch has be running from 1/20 for pass 5-6 hrs and it could not run till 20/20, i not sure whats the problem
same, did you solve this?
when i run this then keras.engine not found erorrs acurs my tensorflow is 2. version and python is 3.11
Use oython 3.6.8 and tensorflow 1.14
one doubt madam, while training the maskrcnn, we have to have same images in train and val folder or different?
different images for training and validation
Ma'am, tensorflow 1.x has been unsupported by Colab. Will it run on tensorflow 2???
This code is compatible with tensorflow 1.x. You can downgrade the pip version of colab and then you can install the tensorflow 1.x
@@CodeWithAarohi I tried but it is suggesting to update the code on tensorflow 2. Can you please upgrde your code? Thanks in advance.
mam the object that i wanted to detect is not there in pretrained models in that case,how would i get cocoweights?.should i necessarily use coco weights? what would i do otherwise?
pls guide mam
If the object you want to detect is not in pretrained weights then collect images related to your custom object, annotate those images in the format which Mask R-CNN accepts. Then train your model on that custom dataset.
You can train in 2 ways-
1- Train the model from scratch.
2- Use pretrained model and then fine tune it with you custom dataset.
Thankyou mam for your concern to take time and reply.one more doubt mam,can i annotate objects after zooming it,,will it cause any performance variation when i use that model in online..can you please tag video on training a model from scratch using mask rcnn.
Hi Aarohi, Is it possible to use the model on only CPU
yes
@@CodeWithAarohi Thank you so much
Hi, How can I change the python version to 3.8.0 in google colab?
Try these commands:
!sudo apt-get update -y
!sudo apt-get install python3.8
!sudo apt-get install python3.8-dev
!sudo apt-get install python3.8-venv
What the python version you used?!
Python 3.6.8
Thanks great work
How did you create a separate environment? And my PC doesn’t have a dedicated GPU how can i run the training this way?
How did you launch the test model file on jupyter notebook? I downloaded the file but I can’t open it!
Kindly help!
You can set GPU_COUNT in config.py file which is in mrcnn folder . And use tensorflow instead of tensorflow-gpu
Thanks for the share, but I have a remark
On this lines :
"assert subset in ["train", "val"]
dataset_dir = os.path.join(dataset_dir, subset)
annotations1 = json.load(open('D:\\env_with_tensorflow1.14\\all_maskrcnn\\maskrcnn_truck_car\\Dataset\\train\\train_json.json'))"
The dataset dir end with '\train' or '\val' but on your 'annotations1' there is only the path to 'train' subset.
The problem is that when the subset will be 'val' the image_path = os.path.join(dataset_dir, a['filename']) on line 95 will be incorrect because a['filename'] access to the file names of the train json image and not the val image.
So if the filename is image_train.jpg the path would be ''...\\Dataset\\val\\image_train.jpg" but on the val_json there is not train image but only "v1","v2" so there will be an error. So its necessary to change the path of the annotations1 according to the subset.
Hi, You have given the path to json file of annotation info of training data but json file for validation data is not given. I faced this error and passed separate json files for train and validation data. Now it starts to train Epoch 1 but I cannot see CPU or GPU consumption. Please help.
how to pass separate json file for validation data?
Hi Aarohi, Thank you very much for this very useful tuto. Actually, I am facing an issue, the bounding boxes are too small, and I do not know how to extend their limits? If you have any idea... Thank you! PL
Hi, Thanks for liking my video and you can do the modifications through the visulize.py file which are present in mrcnn folder.
Ma'am my training has run successfully but during testing when we take random image the box is not appearing and it is appearing in the whole image so ma'am can you suggest me what I need to do now
I need more details like how many classes you are working upon? How many images per class you have etc. Mail me all your project details at aarohisisngla1987@gmail.com
Very nice Aarohi, Pls can you the how to setup the env and necessary pakages and requirement.txt
python==3.6.8 , tensorflow==1.15.0 , Keras==2.2.4 , h5py==2.10.0
i am having python 3.8.0 but many errors are coming due to different version compatiblity , can you give what all versions are required for each library
Follow this video: th-cam.com/video/QP9Nl-nw890/w-d-xo.html and This code is tested on python 3.8.0, tensorflow 2.4.0 and keras 2.3.1
Great job ma'am!!
can u plz do project on face mask detection?
Yes, sure
Do i want to generate separate coco weight file for different images like CT, MRI..etc..?
You need a single json file for all your training images. Ans there can be more than 1 class in your training dataset.
Hello Aarohi (perhaps this is some basic, sorry.) . I'm following this and other tutorials and I would appreciate an orientation on how to create the environment for running this code (as the one you use from min 20:00 onwards). I'm searching an (*.yml) file with the specs on the repo... but in can't find it. thanks in advance!
Install python 3.6.8, then install tensorflow 1.15 , keras 2.2.4, h5py 2.10.0
@@CodeWithAarohi Okay, Ill do that , thanks a lot!
Where can i get the log files?
you will get log folder after training
Hey were you able to get the log files?
As per reply the log files is generated after training but in the code we are using log before training itself, so does that work ?
@@shreyasgupta5514 I have created the log folder before because my coco dataset weights are there. But if you are not putting your coco dataset weights in that log folder then this folder will get created when training starts and epoch wise it will store the trained weights
you dont provide us requirments .txt files
Python 3.6.8, tensorflow 1.14 and h5py 2.10.0
hi,
Wonderful tutorial, I am getting an error ImportError: cannot import name 'AnonymousIteratorV3' from 'tensorflow.python.ops.gen_dataset_ops' how torectify it?'
Tell me the tensorflow, keras and h5py version you are using
@@CodeWithAarohi HDF5 1.8.4, keras (2.8.0) and tensorflow(2.8.0)....
Hello Aarohi, in other implementations to calculate the mAP I have seen that before applying the model.detect function on the image they apply the functions of mold_image from modellib and expand_dims from numpy, to convert the pixel values and to convert the image into only one sample. Using your method I get a higher value of mAP than with the other implementations. Are those steps that I am telling you necessary?
I am not sure about the other methods which you are talking about as I worked with this method only. And I think the approach we are using to get the mAP is correct
I dont have a gpu on my system, does this code work on google colab
Yes
Hi Ma'am, can you provide us the version of tensorflow, keras and python you used for successfully running this code? I did the exact same thing as you mentioned in this video but I am having a error called "ValueError: Tried to covert 'shape' to a tensor and failed. Error: None values not supported."
I am not sure why are you getting this error. I have to see the code
pip install tensorflow == 1.14.0
Hi Aarohi, I have a question to ask:how to lebeling ,detect and classify multiclass in one image using MaskRCNN ?hint,one image has multiclass and also one class has the more than one object so how to leveling them using VIA or how to perpare json file ?
The Process is same. Just create mask for every object present in that image and Assign class name to every object.
@@CodeWithAarohi ok thanks madam,but ,how to lebeling more than one object in one class?for example object1,object2 ,object3,....... etc all are lebeling in one class and also
class2,class3,.....etc
Hello madam, please confirm whether the data in train and validation while creating annotation using VGG annotation should be same or different because i am getting very low detection precision here is the output for detecting KNEE MRI BONE
Processing 1 images
image shape: (1024, 1024, 3) min: 0.00000 max: 64280.00000 int32
molded_images shape: (1, 1024, 1024, 3) min: -123.70000 max: 64176.10000 float64
image_metas shape: (1, 16) min: 0.00000 max: 1024.00000 int64
anchors shape: (1, 261888, 4) min: -0.35390 max: 1.29134 float32
the actual length of the ground truth vect is : 3
the actual length of the predicted vect is : 3
Average precision of this image : 0.0
The actual mean average precision for the whole images 0.0
The images used for training is different than the images used for validation
Hi Aarohi,i am unable to download the class-descriptions-boxable.csv file, train-annotations-bbox.csv file from the command
Can u please help me to fix it?
What is the issue you are facing?
Respected mam , today the second time watching this particular video. Can I use this code to detect brain tumor and liver tumor?
Yes, If you have proper dataset to train then you can use it.
@@CodeWithAarohi Thank You Mam... I will try and give you reply...