Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparing data for training #297

Open
Aptamer1 opened this issue Mar 5, 2018 · 46 comments
Open

Preparing data for training #297

Aptamer1 opened this issue Mar 5, 2018 · 46 comments

Comments

@Aptamer1
Copy link

Aptamer1 commented Mar 5, 2018

Hi,
This is a really great project with great possiblities.

I myself am a medical phd student, consequently my programming knowledge is limited.
I have my own dataset of images with cells, which I want to try and train this model with.

I have used the object detection of google tensorflow before and this worked.
However I have not made a model with masks before, neither can I get pycocotools to work.

I did get the training shapes to work.

I was wondering if someone could explain to me the tools they use on how to make their own dataset fit for this model?
I presume the detection works the same as the tensorflow object detection API, but how do you prepare your mask data? What tools do you use and how should it be prepared for the input?

Any help is greatly appreciated,
Kind regards,
Sören

@fastlater
Copy link

fastlater commented Mar 6, 2018

@Aptamer1 I am at the same point. I just done with the simple shapes demo. Now, I would like to jump to start training with own images and manually prepared masks. Maybe, we can exchange info through the learning process. Can you share your machine specs? Are you using windows? Do you have enough gpu memory?

When I was doing object detection, I used https://github.com/tzutalin/labelImg to annotate the bounding boxes. For annotating mask, the author of this repo mentioned http://labelme.csail.mit.edu/ and http://labelml.com/

I am checking that right now, and see what does the software outputs. Probably, a json file with info about bboxes and masks.
Let me know if you reach this point and figure out something else that I can use too. I guess if we share knowledge, we can make it before the end of this week since preparing data is easy after you know what is the format of the input data and how to input it into the network.

http://cocodataset.org/#download , section 4.1 highlights the coco annotation format. CocoApi includes pycocoDemo where you can see each element of the annotation.

@Aptamer1
Copy link
Author

Aptamer1 commented Mar 6, 2018

@fastlater thanks for the info, I was using the labellmg for the bounding boxes too. For the masks I will look at the tools you sent and see how far I can get.
About my specs - I'm using windows, anaconda/jupyter notebook. Currently my pc has a i7 and a gtx 1070 with 8gb memory.

@fastlater
Copy link

fastlater commented Mar 7, 2018

@Aptamer1 I am using windows + anaconda too. Also, I am not very familiar with python either (I am more familiar with C#) so that is one of the reasons I go very slow reading and understanding the scripts.
According to what I read recently, the segmentation info is defined as list of points (polygon) in the coco format. However, I still dont know how does mask looks like? In vocPascal, masks are painted images where background is painted as black, contours of the shape are painted in white, and the class/instance object is painted in a defined RGB color or painted with a RGB value [classID,classID,classID]. But well, that is semantic segmentation, and this is instance segmentation. I will need to figure out how are the masks in instance segmentation for mask rcnn. Reading issue by issue is helping.

@Aptamer1
Copy link
Author

Aptamer1 commented Mar 7, 2018

@fastlater I think for instance segmentation every mask will be a seperate image. Like the current kaggle data science bowl. Every mask is a binary form of the object you want to detect and each masked object has its own image. Here the masks can also be defined as RLE format, but that is not required for this algorithm.
I do not know how it is going to be for this algorithm. I read that the coco set uses polygon data
I'm currently preparing a small dataset with the labelme tool. I have done the annotation with polygon and masks

*Just finished the annotations. I now have 2 folders, one folder with the masks for each individual object and one with the annotations. The annotations are in xml files, but since I did polygons and masks it seems there are 2 annotations in the file:

> *<object><name>lala</name><deleted>0</deleted><verified>0</verified><occluded>no</occluded><attributes/><parts><hasparts/><ispartof/></parts><date>06-Mar-2018 10:28:39</date><id>4</id><polygon><username>anonymous</username><pt><x>2138</x><y>1068</y></pt><pt><x>2126</x><y>1025</y></pt><pt><x>2156</x><y>1027</y></pt><pt><x>2192</x><y>1063</y></pt><pt><x>2215</x><y>1079</y></pt><pt><x>2255</x><y>1102</y></pt><pt><x>2292</x><y>1120</y></pt><pt><x>2255</x><y>1154</y></pt><pt><x>2255</x><y>1179</y></pt><pt><x>2265</x><y>1215</y></pt><pt><x>2276</x><y>1254</y></pt><pt><x>2317</x><y>1344</y></pt><pt><x>2319</x><y>1385</y></pt><pt><x>2312</x><y>1414</y></pt><pt><x>2283</x><y>1408</y></pt><pt><x>2265</x><y>1356</y></pt><pt><x>2249</x><y>1312</y></pt><pt><x>2224</x><y>1288</y></pt><pt><x>2201</x><y>1256</y></pt><pt><x>2172</x><y>1238</y></pt><pt><x>2165</x><y>1188</y></pt><pt><x>2163</x><y>1161</y></pt><pt><x>2151</x><y>1133</y></pt><pt><x>2144</x><y>1097</y></pt></polygon></object>

> *<mask>opc20170220001_280917_mask_32.png</mask><scribbles><xmin>242.75</xmin><ymin>984.5</ymin><xmax>826.25</xmax><ymax>1920</ymax><

Entire lists per image. I guess I can take the polygon data, it seems this can be converted using pycocotools to coco format - have not checked how yet though: #204
I guess finding this is the next step

This thread #155 mentions that 1 json file is required for all images, apparently there is a conversion code somewhere. After using the labelme tool we get annotation seperately for each image

Not really sure how it looks in the cocodataset. Will look into the issues and algorithm once I can find some more time :)

@fastlater
Copy link

fastlater commented Mar 8, 2018

@Aptamer1 About the coco format, I did my research and inspected the instances_train2014.json using notepad and used the inspect_data.ipynb to check the correspondent output.

One json file includes all the info about dataset, images details, annotations etc as illustrated in the image below:

format

For example (in inspect_data), when
image_ids = [35279]
print(image_ids)

The json file should looks like

{


"info": 
{"description": "COCO 2014 Dataset","url": "http://cocodataset.org","version": "1.0","year": 2014,"contributor": "COCO Consortium","date_created": "2017/09/01"},
"images": [
{"license": 1,"file_name": "COCO_train2014_000000574795.jpg","coco_url": "http://images.cocodataset.org/train2014/COCO_train2014_000000574795.jpg","height": 427,"width": 640,"date_captured": "2013-11-17 10:05:24","flickr_url": "http://farm8.staticflickr.com/7444/8732251722_e68ef5081f_z.jpg","id": 574795},
]
"licenses": [
{"url": "http://creativecommons.org/licenses/by-nc-sa/2.0/","id": 1,"name": "Attribution-NonCommercial-ShareAlike License"},{"url": "http://creativecommons.org/licenses/by-nc/2.0/","id": 2,"name": "Attribution-NonCommercial License"},{"url": "http://creativecommons.org/licenses/by-nc-nd/2.0/","id": 3,"name": "Attribution-NonCommercial-NoDerivs License"},{"url": "http://creativecommons.org/licenses/by/2.0/","id": 4,"name": "Attribution License"},{"url": "http://creativecommons.org/licenses/by-sa/2.0/","id": 5,"name": "Attribution-ShareAlike License"},{"url": "http://creativecommons.org/licenses/by-nd/2.0/","id": 6,"name": "Attribution-NoDerivs License"},{"url": "http://flickr.com/commons/usage/","id": 7,"name": "No known copyright restrictions"},{"url": "http://www.usa.gov/copyright.shtml","id": 8,"name": "United States Government Work"}
]

"annotations": [
{"segmentation": [[89.81,157.37,106.52,139.82,133.67,130.22,147.87,129.38,170.0,129.38,205.92,134.4,215.53,135.65,220.12,141.08,226.81,138.57,236.0,138.57,241.84,138.15,325.8,137.32,340.0,138.15,426.45,136.9,494.53,136.9,580.99,133.56,635.71,132.31,640.0,132.31,638.21,153.19,637.79,154.44,634.45,154.44,629.44,155.7,627.77,163.63,626.93,172.82,625.68,178.25,609.39,182.01,604.8,173.66,593.94,166.56,581.41,157.37,582.66,140.24,571.38,139.82,569.71,151.52,567.63,154.03,555.1,157.37,541.73,164.47,531.71,172.4,527.11,179.92,525.86,198.3,525.86,201.22,446.92,210.83,396.8,217.51,348.77,227.54,313.35,238.39,279.98,245.5,254.55,253.78,218.21,273.83,199.42,281.77,191.9,292.21,184.8,299.31,108.36,304.32,96.67,300.56,100.01,297.22,96.25,290.96,92.49,288.03,87.48,278.01,83.3,267.15,84.14,195.31,85.81,183.61,84.14,182.36,87.06,174.84,88.32,173.17]],"area": 52445.22554999998,"iscrowd": 0,"image_id": 574795,"bbox": [83.3,129.38,556.7,174.94],"category_id": 7,"id": 174538},
{"segmentation": [[367.82,284.4,367.28,277.68,369.28,272.04,372.91,269.13,376.91,271.13,384.0,276.77,384.0,282.95,374.55,284.77]],"area": 194.72660000000016,"iscrowd": 0,"image_id": 574795,"bbox": [367.28,269.13,16.72,15.64],"category_id": 10,"id": 1384486},
{"segmentation": [[608.57,419.21,618.69,405.67,635.51,403.96,639.64,407.38,639.93,421.63,608.57,422.06]],"area": 450.5545499999987,"iscrowd": 0,"image_id": 574795,"bbox": [608.57,403.96,31.36,18.1],"category_id": 13,"id": 1809392}
]

"categories": [
{"supercategory": "person","id": 1,"name": "person"},{"supercategory": "vehicle","id": 2,"name": "bicycle"},{"supercategory": "vehicle","id": 3,"name": "car"},{"supercategory": "vehicle","id": 4,"name": "motorcycle"},{"supercategory": "vehicle","id": 5,"name": "airplane"},{"supercategory": "vehicle","id": 6,"name": "bus"},{"supercategory": "vehicle","id": 7,"name": "train"},{"supercategory": "vehicle","id": 8,"name": "truck"},{"supercategory": "vehicle","id": 9,"name": "boat"},{"supercategory": "outdoor","id": 10,"name": "traffic light"},{"supercategory": "outdoor","id": 11,"name": "fire hydrant"},{"supercategory": "outdoor","id": 13,"name": "stop sign"},{"supercategory": "outdoor","id": 14,"name": "parking meter"},{"supercategory": "outdoor","id": 15,"name": "bench"},{"supercategory": "animal","id": 16,"name": "bird"},{"supercategory": "animal","id": 17,"name": "cat"},{"supercategory": "animal","id": 18,"name": "dog"},{"supercategory": "animal","id": 19,"name": "horse"},{"supercategory": "animal","id": 20,"name": "sheep"},{"supercategory": "animal","id": 21,"name": "cow"},{"supercategory": "animal","id": 22,"name": "elephant"},{"supercategory": "animal","id": 23,"name": "bear"},{"supercategory": "animal","id": 24,"name": "zebra"},{"supercategory": "animal","id": 25,"name": "giraffe"},{"supercategory": "accessory","id": 27,"name": "backpack"},{"supercategory": "accessory","id": 28,"name": "umbrella"},{"supercategory": "accessory","id": 31,"name": "handbag"},{"supercategory": "accessory","id": 32,"name": "tie"},{"supercategory": "accessory","id": 33,"name": "suitcase"},{"supercategory": "sports","id": 34,"name": "frisbee"},{"supercategory": "sports","id": 35,"name": "skis"},{"supercategory": "sports","id": 36,"name": "snowboard"},{"supercategory": "sports","id": 37,"name": "sports ball"},{"supercategory": "sports","id": 38,"name": "kite"},{"supercategory": "sports","id": 39,"name": "baseball bat"},{"supercategory": "sports","id": 40,"name": "baseball glove"},{"supercategory": "sports","id": 41,"name": "skateboard"},{"supercategory": "sports","id": 42,"name": "surfboard"},{"supercategory": "sports","id": 43,"name": "tennis racket"},{"supercategory": "kitchen","id": 44,"name": "bottle"},{"supercategory": "kitchen","id": 46,"name": "wine glass"},{"supercategory": "kitchen","id": 47,"name": "cup"},{"supercategory": "kitchen","id": 48,"name": "fork"},{"supercategory": "kitchen","id": 49,"name": "knife"},{"supercategory": "kitchen","id": 50,"name": "spoon"},{"supercategory": "kitchen","id": 51,"name": "bowl"},{"supercategory": "food","id": 52,"name": "banana"},{"supercategory": "food","id": 53,"name": "apple"},{"supercategory": "food","id": 54,"name": "sandwich"},{"supercategory": "food","id": 55,"name": "orange"},{"supercategory": "food","id": 56,"name": "broccoli"},{"supercategory": "food","id": 57,"name": "carrot"},{"supercategory": "food","id": 58,"name": "hot dog"},{"supercategory": "food","id": 59,"name": "pizza"},{"supercategory": "food","id": 60,"name": "donut"},{"supercategory": "food","id": 61,"name": "cake"},{"supercategory": "furniture","id": 62,"name": "chair"},{"supercategory": "furniture","id": 63,"name": "couch"},{"supercategory": "furniture","id": 64,"name": "potted plant"},{"supercategory": "furniture","id": 65,"name": "bed"},{"supercategory": "furniture","id": 67,"name": "dining table"},{"supercategory": "furniture","id": 70,"name": "toilet"},{"supercategory": "electronic","id": 72,"name": "tv"},{"supercategory": "electronic","id": 73,"name": "laptop"},{"supercategory": "electronic","id": 74,"name": "mouse"},{"supercategory": "electronic","id": 75,"name": "remote"},{"supercategory": "electronic","id": 76,"name": "keyboard"},{"supercategory": "electronic","id": 77,"name": "cell phone"},{"supercategory": "appliance","id": 78,"name": "microwave"},{"supercategory": "appliance","id": 79,"name": "oven"},{"supercategory": "appliance","id": 80,"name": "toaster"},{"supercategory": "appliance","id": 81,"name": "sink"},{"supercategory": "appliance","id": 82,"name": "refrigerator"},{"supercategory": "indoor","id": 84,"name": "book"},{"supercategory": "indoor","id": 85,"name": "clock"},{"supercategory": "indoor","id": 86,"name": "vase"},{"supercategory": "indoor","id": 87,"name": "scissors"},{"supercategory": "indoor","id": 88,"name": "teddy bear"},{"supercategory": "indoor","id": 89,"name": "hair drier"},{"supercategory": "indoor","id": 90,"name": "toothbrush"}
]

}

If more images, more elements will be included in the lists of images and annotations. I want to test it with at least 2 or 3 images with 2 or 3 clear instances per images. As you can see from code above, your list of points <pt><x>2138</x><y>1068</y></pt><pt><x>2126</x><y>1025</y> ....needs to be converted into a list of consecutive numbers "segmentation": [[2138,1068,2126,1025,....]]

@Aptamer1
Copy link
Author

Aptamer1 commented Mar 8, 2018

@fastlater Thanks for the great info, I will look into this to see if I can find a way to convert the polygons to the json format.
So If I get it right from this issue: cocodataset/cocoapi#111
This script should convert the polygon masks which you get from labelme tool from MIT to a right format: https://github.com/nightrome/cocoapi/blob/master/PythonAPI/cocostuff/pngToCocoResultDemo.py

I will have a look at it later today and see what the output is, after I install pycocotools

Or we need to look for a script that converts PASCALVOC (output from labelme?) to MS COCO, it's easy to find a mscoco to pascal but not other way around

@fastlater
Copy link

fastlater commented Mar 8, 2018

@Aptamer1 When you done the test, let me know what does the script outputs.

@fastlater
Copy link

fastlater commented Mar 9, 2018

@Aptamer1 I want to share this repo: https://github.com/killthekitten/kaggle-ds-bowl-2018-baseline
It is an adapted version of this one. The interesting thing is, I dont see json annotations there. Just raw images and mask images.
Notice that "these masks are whole-image masks, one for each object instance". Well, we still need to prepare the mask so we haven't lose our time doing that.
In case only masks images are needed, how to input masks for 2 classes? Their demo only has 1 class to detect so mask is [255,255,255].

@Aptamer1
Copy link
Author

Aptamer1 commented Mar 11, 2018

@fastlater That repo looks interesting, might be worth checking out as an easier alternative.
For my problem I only want to start with one class too, afterwards expand to a second class.

Still trying to install pycocotools, have not had a lot of time to get it installed, probalby will find some time later this week.
Will keep you updated.

pycocotools keeps giving an error that it cannot find the pyococotools._mask, there are some issues that are relating to the same problem, but they do not seem to help for me. Will try again later this week on my pc at home.

For now I will look into the algorithm from kaggle which you sent

@ronh2106
Copy link

Hi guys,

I just stumbled upon your discussion. I am also a newbie and wanted to try to apply the Mask R-CNN algorithm to the Kaggle DS Bowl 2018 data. I wanted to ask if anyone of you has already succeeded with this? Maybe we could help each other via skype/TV and exchange experiences?

Thanks!

@fastlater
Copy link

@r0nh there is a baseline demo using this repo in that kaggle challenge forum.

@ronh2106
Copy link

@fastlater

Do you mean this one: https://github.com/killthekitten/kaggle-ds-bowl-2018-baseline

Did you manage to run it on your own dataset?

@fastlater
Copy link

@r0nh It does work fine.

@Aptamer1
Copy link
Author

@fastlater got my pc back up and running and can spend some time again on this project.
You manage to get the kaggle algorithm working on your own set?

I just got pycocotools working and am looking into this algorithm.
I currently have a folder with images a folder with annotations and a folder with masks. I already found that this algorithm will extract bounding boxes from masks.

this line is giving me an error; id_extractor = re.compile(f"{base_path}{os.sep}(?P<image_id>.){os.sep}masks{os.sep}(?P<mask_id>.).png")
I guess this line refers to the path of the masks, but it gives an error
not really sure which lines to changes so it can find my path with the images/masks, which lines did you change to correspond to your own data?

@fastlater
Copy link

@Aptamer1
As I mentioned, that project script does work fine for any dataset of images with masks. However, I have no idea how does it work without need annotations. I guess it is because the script load the images and mask from predefined folder names. It does work fine for 1 class detection but I want to detect more than 1 class. I still don't know what to change to make it work for more than 1 class. Do you need multi-class segmentation too?

About the error, I don't remember to have issues in that line but since you are using windows, you remember that I had to add these 2 lines in bowl_dataset.py
mask_path = mask_path.replace("\\", "/") #for windows
and
image_path = image_path.replace("\\", "/")

I recommend you to "abuse" of print() function. Place print in many different locations so you will go understanding more and more over time.

@Aptamer1
Copy link
Author

Aptamer1 commented Mar 19, 2018

@fastlater thanks for the tip, I will try out some things later after work
Preferably I'd also like to do multiclass segmentation, however starting with this is already a good start :)

@fastlater
Copy link

@Aptamer1

Preferably I'd also like to do multiclass segmentation

We are in the same boat. I guess it will be possible but the script was prepared to work for 1 class only so there will be job to do I guess. I opened an issue there about how to do multi-class segmentation with their script but they told me to check the shapes demo.

Let me know if you solve the problem using the tip.

@Paulito-7
Copy link

Paulito-7 commented Mar 20, 2018

@fastlater

According to the shapes notebook example you have to mention as many masks (0 for background, 1 for the instance) as instances you have, no matter the class of the object.
I am not sure to remember how to make them correspond to the right class, will check it later and come back to you.

@Abduoit
Copy link

Abduoit commented Mar 20, 2018

Hello guys @Aptamer1 @fastlater

I trained my own images using object detection API Pascal VOC and ssd_mobilenet_v1_coco_11_06_2017, I used labellmg tool for annotating bounding boxes.

Now I want to do semantic segmentation and instance segmentation.
Can I follow same steps for object detection API except I should use this annotating tool and I should also use different pipeline.config for example mask_rcnn_inception_v2_coco_2018_01_28 ??

@Aptamer1
Copy link
Author

@Abduoit That annotation tool can be used, I was using the mit labelme annotation but either is ok I guess

About the steps, I'm still figuring them out myself.
The matterport algorithm requires a specific input of your annotations in a JSON file (still figuring out how to get this done, I have linked a script in this post that might help: This script should convert the polygon masks which you get from labelme tool from MIT to a right format: https://github.com/nightrome/cocoapi/blob/master/PythonAPI/cocostuff/pngToCocoResultDemo.py)

I'm now trying out the killthekitty algorithm, here you need the masks and your original images and the algorithm will make the bounding boxes. I have not had time yet to try this on my own dataset, figuring out where to put my input files so I can try and run the algorithm, since I'm not a programmer it takes quite some time for me to figure this out, however fastlater did say he got it working.

Please join the discussion and if you figure something out let us know :)

@Paulito-7
Copy link

@Aptamer1 @Abduoit Matterport's blog should tell you what sort of JSON file you can directly use, starting from the balloon example : https://engineering.matterport.com/splash-of-color-instance-segmentation-with-mask-r-cnn-and-tensorflow-7c761e238b46

@fastlater
Copy link

fastlater commented Mar 21, 2018

@Paulito-7 Thank you for your comment. Any feedback is appreciated. I succesfully tested mask rcnn for 1 class segmentation using my own dataset (using killthekitty code) . Now, I would like to try the multi-class segmentation and I am also trying to figure out how to make the mask correspond to the right class. I dont know if I need to paint them of a different colour or just notify the script that x mask belong to y class. I will be working on it since today. Lets keep in touch and please share with us if you figure it out before me.

@Abduoit As mentioned in the blog of the project (link shared in the previous comment), there isn’t a universally accepted format to store segmentation masks. This repo uses a single json file to load the segmentation data as polygon points (+image info + bounding box + etc). killthekitty algorithm save them as PNG images (each sample has a folder named images and a folder named masks). I will keep trying with the killthekitty code for multi-class task but if I get too many problems, I will go back to the original script and input the masks as polygon points since the original script is already working for multiclass instance segmentation.

@waleedka
Copy link
Collaborator

I wrote a blog post about this repo, and I made a point to cover how to build your own dataset. The code from the blog post is in the samples/balloons folder. Hope it helps answer some of the questions in this thread.

https://engineering.matterport.com/splash-of-color-instance-segmentation-with-mask-r-cnn-and-tensorflow-7c761e238b46

@John1231983
Copy link

@waleedka : This is very useful. Could you tell me the reason why I make a bounding box from the mask with different 6 pixels give lower performance than 1 pixel?

To validate this approach, we compared our computed bounding boxes to those provided by the COCO dataset. We found that ~2% of bounding boxes differed by 1px or more, ~0.05% differed by 5px or more, and only 0.01% differed by 10px or more.

def extract_bboxes(mask):
   ...
            x2 += 3 
            y2 += 3
            x1-=3
            y1-=3
...

@fastlater
Copy link

@John1231983 I dont think this is the thread to post that question. We are discussing about how to prepare the data. Can you please ask your question in a different issue?

@Paulito-7
Copy link

Paulito-7 commented Mar 21, 2018

@fastlater
I just managed to generate my own masks for a 2-class problem, will check tomorrow if I can train on my own dataset and will keep you informed about it.
I had to do some changes on the label retrieval (inspiring myself from both shapes and balloon examples).

@fastlater
Copy link

@Paulito-7 Thank you for your feedback. I was working in another issue yesterday so I ran out of time. Keep in touch and lets see if we can find the best solution to this.

@Paulito-7
Copy link

@fastlater
I could set a training today and masks were generated right.
I just needed to define my own config, and redefine the dataset class from the balloon example.
Then just add a classnames retrieval from the json file (generated by VIA tool) to the load_data function and store it in a class_ids variable that you return in load_mask, and it should work then !

@fastlater
Copy link

@Paulito-7 I have been inspecting the code, especially the load_mask function and I think the only variable to change is class_ids.

@LinHowjia
Copy link

LinHowjia commented Mar 23, 2018

I am also trying to train my own dataset. Because the memory of GPU is not big enough, I clipped images (1920x1080 pixel) into 256x256 pixel as training dataset to train the model, but when I use the model to detect images (1920x1080 pixel), the test result show "No instances to display error"! Is it because I clipped images into 256x256 to train the model?

@Abduoit
Copy link

Abduoit commented Mar 24, 2018

Hi @waleedka @Aptamer1
I used balloon example for training with my own images, I did annotation then I start training with 8GB GPU. I used only 30 images, I know it is not enough but I got good results, I could improve it by increasing the images. Thanks @waleedka and your team for your effort.

Do you guys know how to run it using my own file .h5 that I trained. Testing an image or doing real time with webcam.

I keep getting this error.

ValueError: Dimension 1 in both shapes must be equal, but are 324 and 8. Shapes are [1024,324] and [1024,8]. for 'Assign_682' (op: 'Assign') with input shapes: [1024,324], [1024,8].

Thanks

@Aptamer1
Copy link
Author

I just finished training my own dataset for one class and it worked using the balloon example.
For visualization I used the demo jupyter notebook code and adjusted it accordingly.

@Abduoit
Copy link

Abduoit commented Mar 25, 2018

@Aptamer1
I also trained it with my own images for one class using balloon example.

How did you adjust demo jupyter notebook code, I tried to replace file .5h with my own file, but I am getting the following error. I think it is in COCO.py.

ValueError: Dimension 1 in both shapes must be equal, but are 324 and 8. Shapes are [1024,324] and [1024,8]. for 'Assign_682' (op: 'Assign') with input shapes: [1024,324], [1024,8].

@Aptamer1
Copy link
Author

@Abduoit what I did was copy the balloon.py file and did a replace (text) balloon with the object I wanted to find. After this I trained the file and did the same in the demo file.

The algorithm will ask for coco in default, you can adjust it to your own file (just only replace the last part of the file name like this: mask_rcnn_coco.h5 ==> mask_rcnn_balloon.h5) I just left it at coco :)

I think the demo file will also by default go to images directory, here you can put the images you want to use your detection algorithm on.

If this is unclear I can send you my demo file

@Abduoit
Copy link

Abduoit commented Mar 26, 2018

@Aptamer1
I did exactly you said. I used balloon example to train the model with my own images and everything works fine. But when I try to run demo.ipynb with file .h5 that I got after training, I get the following error
ValueError: Dimension 1 in both shapes must be equal, but are 324 and 8. Shapes are [1024,324] and [1024,8]. for 'Assign_682' (op: 'Assign') with input shapes: [1024,324], [1024,8].

I even tried to replace mask_rcnn_coco.h5 to file mask_rcnn_balloon.h5 that I downloaded from here but I still get same error.
If you please send me your files to my email [email protected]. I want to check how did you write the new class name. like this class_names = ['Balloon'] ?

@rafisef
Copy link

rafisef commented Mar 27, 2018

Hey guys I stumbled across this forum and am also trying to train my own dataset. I already have a few images and their respective segmentation masks. I noticed that the mask has to be in the format [height, width, # of instances] but when I load my mask image (which is already black and white) it always comes back in the rgb space and I can't update the 3rd channel to be the number of instances. Does anyone else have this issue?

@Chasesc
Copy link

Chasesc commented Apr 9, 2018

@Abduoit Did you find a solution to your problem? Make sure your InferenceConfig matches the Config you used to train. Check to see if they have the same number of classes.

@Abduoit
Copy link

Abduoit commented Apr 9, 2018

@Chasesc
yes, I still have same problem,

In coco.py there is

# Number of classes (including background)
NUM_CLASSES = 1 + 80 # COCO has 80 classes

For me when I trained it with only one class I have like this

# Number of classes (including background)
NUM_CLASSES = 1 + 1 # COCO has 1 class

Is this correct ? is this what do you mean ?

@Chasesc
Copy link

Chasesc commented Apr 9, 2018

Ensure your InferenceConfig also only has two classes. (Like your training config) For example,

class InferenceConfig(Config):
	NAME = "inference"
	NUM_CLASSES = 2
	GPU_COUNT = 1
	IMAGES_PER_GPU = 1

config = InferenceConfig()
config.display()

model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)

I believe the problem is that your inference config had the incorrect number of classes.

@Venky-Iyer
Copy link

Venky-Iyer commented Apr 10, 2018

Hi... I am also facing a similar problem. I am trying to use the Mask R-CNN for a different database. When I try running the model, I get the following error:

ValueError: Dimension 1 in both shapes must be equal, but are 264 and 324. Shapes are [1024,264] and [1024,324]. for 'Assign_376' (op: 'Assign') with input shapes: [1024,264], [1024,324].

I get this error when I run the network with a Resnet50 backend. While running the network with a Resnet101 backend, the error is similar but the 'Assign_376' gets changed to 'Assigned_682'.

Can someone please suggest what could be the reason.

Thanks in advance.

@Chasesc
Copy link

Chasesc commented Apr 10, 2018

@Venky-Iyer Did what I suggested not work?

@Venky-Iyer
Copy link

Venky-Iyer commented Apr 10, 2018

Hi @Chasesc

It is loading the weights now... I had not excluded certain layers while loading the weights. Thanks for your help.

@siddheshgunjal
Copy link

siddheshgunjal commented Aug 11, 2018

Hello, I'm trying to train on my own dataset. I have prepared and annotated my data with VIA Image annotating tool. but while verifying my data with my own inspect_data.ipynb file I am getting error as AttributeError: 'list' object has no attribute 'values' from 2 days I am trying to resolve this error but had no success.

`AttributeError Traceback (most recent call last)
in ()
3 # https://github.com/matterport/Mask_RCNN/releases
4 dataset = window.WindowDataset()
----> 5 dataset.load_window(WINDOW_DIR, "train")
6
7 # Must call before using the dataset

~\Desktop\Mask_RCNN\samples\window\window.py in load_window(self, dataset_dir, subset)
93 # the outline of each object instance. There are stores in the
94 # shape_attributes (see json format above)
---> 95 polygons = [r['shape_attributes'] for r in a['regions'].values()]
96
97 # load_mask() needs the image size to convert polygons to masks.

AttributeError: 'list' object has no attribute 'values'`

Please Help Me Out!

@corekms
Copy link

corekms commented Aug 21, 2018

@siddheshgujal
Are you using VGG image annotator 2.0?
If you are using 2.0 with "regions" as list format, recreate json file with via1.0 which writes dictionary format of "regions".
You can also rewrite json file on your own though, it might make you tired.

@FabiolaL09
Copy link

@siddheshgunjal could you fix the problem?
I made my notes using VIA 2.0 (130 images) so I don't want to have to re-label all of them

@siddheshgunjal
Copy link

@siddheshgunjal could you fix the problem?
I made my notes using VIA 2.0 (130 images) so I don't want to have to re-label all of them

I had to use VIA 1.0 because editing the json file is bigger pain than that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests