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...
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 😊🙏
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.
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?
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.
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
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.
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.
@@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
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.
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!
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
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?
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?
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, 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?
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')))
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
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.
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
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??
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.
hi, thank you for your helpful video; i jae a question , hope you can give me a guide. i tried to apply this code, first it was the problem of tensorflow 1x version not being abled in colab, then i made a virtual env using lower python version and using tensorflow 1x , it appeared with other errors such as skimage and code being old! i wish you have sth for me to do it,,, the other help that i want is about models detecting polygon with polygon annotations; i want to detect polygon lables exactly as polygons, not as bounding boxes (when the model detect my thing, it shows it as a polygon label not a bounding box label), do you have any clue for me? or do you know on which models should i work? i'll be so thankful anyway💕💕
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
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
@@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'
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")
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!
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?
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 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 using Labelme annotation tool to annotate the images to prepare a .json file. I am having a problem in the loop (for a in annotations), can you guide what could be done??
@@bhatiapkaur No idea, I was using labelme annotation toll earlier for data labelling, but now have shifted to CVAT Annotation tool and its the best annotation tool I have used so far. I was preparing a model based on using Mask-RCNN earlier but now am working on developing a model using U-Net architecture
Your videos are awesome. Ma'am, I will be really grateful if you make a video about how to set up the environment to run this MaskRCNN with a GPU of nvidia 30 series, Thank you.
Hello mam!! First of all thankyou soo much for the wonderful explanation!! Google colab actually doesnt support older tensorflow 1.x versions anymore , So the code shows a lot of errors.. Can you please give us the upgraded code!! We have a deadline to complete our project mam.. Thanks in advance :)
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.
Hi Aarohi, i have a question. so, from this line: annotations1 = json.load(open('D:\\env_with_tensorflow1.14\\all_maskrcnn\\maskrcnn_truck_car\\Dataset\\train\\train_json.json')) my understanding is that we only use the training annotations. so how do we us the val annotations? or when? because I didn't see it called. Thank you
Hi, somebody had this error when trying to train the model: "TypeError: cannot pickle 'generator' object ForkingPickler(file, protocol).dump(obj)". I also have this warning "WARNING:tensorflow:Model failed to serialize as JSON. Ignoring... cannot pickle '_thread.RLock'". Thank you a lot.
I'm using anaconda to run the program, and I have library and module compatibility issue, is there any reference on what libraries this mask-rcnn run on?
@@CodeWithAarohi Hi thank you for replying, I still haven't solved it. The compatibility problem occurred usually when my TensorFlow, scikit, OpenCV, etc don't match the version that the code is importing and it keep crashing every time I tried to lower the version. So maybe you can share your environment set up like what version of python, TensorFlow, scikit or anything that needed to be installed on your virtual environment
@@CodeWithAarohi Also I do notice that there is requirement.txt but there is still some incompatibility with the present update and some are not detailed with what version should be used
Mam, I am running the code on MacOS and now getting any file generated under logs folder. Instead, I am getting warning as : I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA. Could you please suggest?
Thank you for your explanation. I'm executing the test_truck_car_model.ipynb with own datasets. When I want to perform the prediction, which predict images which are not present in dataset, the result showed "No instances to display". Do you have any idea about this error?
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.
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
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
I am in USA and working on imaging. I appreciate you highly. You did a great job. Excellent
Thank you so much 😀
very neat, clear, and simple explanation.. Keep it up madam
Thank you so much 🙂
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 😊
A very clear explanation mam.. Thanks a lot...Live long ....
Glad my video is helpful!
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...
YOU ARE THE BEST WOMAN IN THE WORLD!)))
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
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.
Wow. Very nicely explained
Glad you liked it
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.
Amazing explaination. Super helpful; thank you!
Glad it was helpful!
hai ma'am i have error in may program after training, the error like this
UnboundLocalError: local variable 'image_id' referenced before assignment
thank you so much you dont how much you are helping me right now God bless you
Glad to hear 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?
Thank you so much❤ This video helps me a lot to complete my research.
Glad it was helpful!
Great job, Ma'am!!
Thank you! 😊
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.
Amazing sis
Thanks 😊
i want to train Mask-RCNN on python 3.9.7 ..please can you share the requirements.txt?
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!
mam what if i have different json file from each images? how do i train a mask rcnn
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.
how to display matrix, and accuracy?
Ma'am can you tell us where we need to see accuracy in the training
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.
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
indebted to you maam .
Glad my video is helpful :)
Mam in which file i have to perform preprocessing techniques mam Please reply mam??
How can we show this on like Vscode using python?
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
please make the video on the HAM10000 dataset for skin lesion that how to import this dataset and use it.
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.
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!
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
Hello mam
You explain the concept of MRCNN so good,
It's my request to you plz give the demo of same mask rcnn on any video file.
Will upload soon
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.
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
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
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
It is showing warning: you are using default load mask(),may be you need to define your own one...repeatedly..plz help
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.
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
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?
Does mask rcnn supports binary mask as training in json file?
No
@@CodeWithAarohi how about RLE json annotation format?
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')))
if you get long data set how to validation
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
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: ruclips.net/video/QP9Nl-nw890/видео.html
Best RUclips channel / Platform to learn Artificial Intelligence , Data Science , Data Analysis , Machine Learning.
#BestChannel #RUclipsChannel #ArtificialIntelligence #CodeWithAarohi #DataScience #Engineering #MachineLearning #DataAnalysis #BestLearning #LearnDataScience #DataScienceCourse #AytificialIntelligenceCourse #Codewithaarohi #CodeWithAarohi Code with Aarohi
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
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
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
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?
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: ruclips.net/video/QP9Nl-nw890/видео.html and This code is tested on python 3.8.0, tensorflow 2.4.0 and keras 2.3.1
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
Hi mam, I want to know how can we compute the feature map of mask rcnn? Any code or help you can give.thanks
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.
Can you please mention the versions u use?
hi, thank you for your helpful video; i jae a question , hope you can give me a guide.
i tried to apply this code, first it was the problem of tensorflow 1x version not being abled in colab, then i made a virtual env using lower python version and using tensorflow 1x , it appeared with other errors such as skimage and code being old!
i wish you have sth for me to do it,,,
the other help that i want is about models detecting polygon with polygon annotations;
i want to detect polygon lables exactly as polygons, not as bounding boxes (when the model detect my thing, it shows it as a polygon label not a bounding box label), do you have any clue for me? or do you know on which models should i work? i'll be so thankful anyway💕💕
You can perform instance segmentation with other models also like YOLO11. Here is a tutorial: ruclips.net/video/SwG9BSWIpBs/видео.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
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
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.
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
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.
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
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?
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
Great job ma'am!!
can u plz do project on face mask detection?
Yes, sure
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.
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
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.
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??
Does this work with tensorflow 2.x. I noticed that in your directory the active version of tensorflow is 1.14?
This code work with tensorflow 1.14
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
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!
Welcome :)
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.
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?
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.
Which tensorflow and keras version are you using for this particular project, because I am getting problems with versions of tf and keras.
tensorflow 1.15, keras 2.2.5, h5py 2.10.0
@@CodeWithAarohi Thank you mam. and can you please tell us the python version as well.
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.
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
I got data of 30k. what should i do?
I am using Labelme annotation tool to annotate the images to prepare a .json file. I am having a problem in the loop (for a in annotations), can you guide what could be done??
It is storing the content in .json file in a different way than how VGG annotator saves a .json file
annotation should be in coco format using polygon shape
@@puranjitsingh1782 i have used plain sight annotation tool for large dataset, but facing same problem with .json format, any suggestions?
@@bhatiapkaur No idea, I was using labelme annotation toll earlier for data labelling, but now have shifted to CVAT Annotation tool and its the best annotation tool I have used so far. I was preparing a model based on using Mask-RCNN earlier but now am working on developing a model using U-Net architecture
Your videos are awesome.
Ma'am, I will be really grateful if you make a video about how to set up the environment to run this MaskRCNN with a GPU of nvidia 30 series, Thank you.
Process is similar as we do for other GPU's
Hello mam!!
First of all thankyou soo much for the wonderful explanation!!
Google colab actually doesnt support older tensorflow 1.x versions anymore , So the code shows a lot of errors..
Can you please give us the upgraded code!!
We have a deadline to complete our project mam..
Thanks in advance :)
ruclips.net/video/QP9Nl-nw890/видео.html
Hi Arohi, at 5:53 minutes, you told we need draw line on object. if i have 1 lac images then do i need to mask all the images or else only for few?
Yes you have to do annotations for all the images
@@CodeWithAarohi Then how it works in the live video??
@@manoharnookala4212 same doubt ... how we can annotate n number of files??
@@sangavisivanandham2737 have you got any solution to this, if i have a large dataset then how to do annotations for all images?
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.
Hi Aarohi, i have a question. so, from this line:
annotations1 = json.load(open('D:\\env_with_tensorflow1.14\\all_maskrcnn\\maskrcnn_truck_car\\Dataset\\train\\train_json.json'))
my understanding is that we only use the training annotations. so how do we us the val annotations? or when? because I didn't see it called.
Thank you
You can use if else statement and can call train.json from train and val folder.
Hi, somebody had this error when trying to train the model: "TypeError: cannot pickle 'generator' object ForkingPickler(file, protocol).dump(obj)". I also have this warning "WARNING:tensorflow:Model failed to serialize as JSON. Ignoring... cannot pickle '_thread.RLock'". Thank you a lot.
I'm using anaconda to run the program, and I have library and module compatibility issue, is there any reference on what libraries this mask-rcnn run on?
What is the issue you are facing?
@@CodeWithAarohi Hi thank you for replying, I still haven't solved it. The compatibility problem occurred usually when my TensorFlow, scikit, OpenCV, etc don't match the version that the code is importing and it keep crashing every time I tried to lower the version. So maybe you can share your environment set up like what version of python, TensorFlow, scikit or anything that needed to be installed on your virtual environment
@@CodeWithAarohi Also I do notice that there is requirement.txt but there is still some incompatibility with the present update and some are not detailed with what version should be used
I don't have a GPU on my PC, can you share a video that runs on google Colab?
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, Is it possible to use the model on only CPU
yes
@@CodeWithAarohi Thank you so much
Mam, I am running the code on MacOS and now getting any file generated under logs folder. Instead, I am getting warning as : I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA. Could you please suggest?
you can ignore the warning. Warning will stop your code processing
@@CodeWithAarohi I was able to solve the issue. I am not getting any errors but model files are also not getting created under logs folder.
Thank you for your explanation. I'm executing the test_truck_car_model.ipynb with own datasets. When I want to perform the prediction, which predict images which are not present in dataset, the result showed "No instances to display". Do you have any idea about this error?
"No instances to display" means objects are not detected. You need to improve your model. Try to increase dataset , epochs
@@CodeWithAarohi thanks so much for replying
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
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