Giter VIP home page Giter VIP logo

building-detection-maskrcnn's Introduction

Building-Detection-MaskRCNN v2.0

The aim of this project is to detect the buildings from the bird's-eye view pictures. I used SpaceNet dataset as a dataset. Because I had limited time, matterport's Mask RCNN implementation was used not to waste time by coding all the details of Mask-RCNN.

  • If you only need pretrained weight file, leave a star for this project and send an email to [email protected]. I will respond in 5-6 hours (As soon as possible).
  • If you need more clarification or have any question please open an issue first.
  • If the files are not opened, click nbviewer and copy+paste the files' link

You may want to check all the Results of version 2.0.

TestResult_v2/Test1.png TestResult_v2/Test2.png TestResult_v2/Test3.png TestResult_v2/Test8.png

Here is an output from version 1.0 (See how the model was improved.) (All former outputs): TestResult/successful (1).png

Project is divided into 5 steps:

1- Download the SpaceNet Dataset

To download the dataset on your computer, visit the SpaceNet's website, and check the 'Dependencies'. As it says, you need to have an AWS account, then download the AWS Command Line Interface (CLI). In this project, I downloaded the SpaceNet Buildings Dataset V2, but only used 'AOI 2 - Vegas' part of it. Then, copy-paste the commend lines that are shown on the web page to CLI.

2- What is Mask-RCNN?

To comprehend what MRCNN is you can read this paper. Here are some helpful websites that helped me out a lot;

3- From Theory to Implementation

Okay, we got the idea of the MRCNN, but how are we going to impelement those theoretical stuff to real code? If you are not concerned with time, please try to implement by yourself. However, I had limited time for this project. So, I used matterport's Mask RCNN implementation. You can search and find other implementations. Do not forget to check the projects that are on matterport's Mask RCNN page. Also, it is possible to search similar projects and read thier codes. It will improve your coding skill.

4- Preprocess the Data

After you download the dataset, you can check how geojson files look like by running Display_GeoJSON.ipynb

While I was striving to complete this project, I got lots of errors because of the name of the training files. After you download the training dataset, you will notice that the name of files are not in order. I mean, the data includes 'RGB-PanSharpen_AOI_2_Vegas_img1.tif' and 'RGB-PanSharpen_AOI_2_Vegas_img3.tif' but 'RGB-PanSharpen_AOI_2_Vegas_img2.tif'. So, We need to put them in order. To do this, you can run Rename_Files.ipynb

We have the dataset and its files' name are in order, but its format it TIFF. So, I converted TIFF file to the RGB file by running TIF_to_PNG.py

To train the model, we need the labels, too. We will create these labels by using TIFF files and its corresponding GeoJSON files. We need the TIFF file to adjust the position of the GeoJSON coordinates to the specific picture. You only need to follow Create_Masks.ipynb

If you want to see RGB and its corresponding Mask, run Display_Mask_and_RGB_Image.ipynb

5- Training the Model & Testing

To train the model, you need to know what size of model your computer can work with. For example, I was using 'resnet101' as a backbone, but I got OOM (Out Of Memory) error, then I reduced it to the 'resnet50'. If it is possible, try to work with 'resnet101'. Also, do not forget to adjust configuration part regarding to your computer and dataset. Please analyze the SpaceNet_train.py part. Another thing that may be helpful for you, I share my trained h5 file (leave a star for this project and send an email to the mail-address below). I trained 151 epoach for 'all' part of the model.

That's it. If you need more clarification or have any question please open an issue.

building-detection-maskrcnn's People

Contributors

mstfakts avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

building-detection-maskrcnn's Issues

Need help to load the Pre-trained Model

Hello,

Trying your code from here: https://github.com/Mstfakts/Building-Detection-MaskRCNN for one of my Engineering-final-year project. I downloaded the pre-trained model from here: https://drive.google.com/file/d/1X-vodJEXvnu6uEn0TDLt1VhHkT17eOkG/view

I am trying to load the model like I have done for 'Image Classifier using CNN' project, where I loaded the model (keras.model.load_model), then loaded the test image (keras.preprocessing.image.load_img), then made the model predict ( keras.model.load_model .predict), then displayed the prediction.

Trying the above process for your code gives an error as follows:


runfile('D:/python/building_detection/7_Building-Detection-MaskRCNN-master/load_model.py', wdir='D:/python/building_detection/7_Building-Detection-MaskRCNN-master')
Traceback (most recent call last):

File "D:\python\building_detection\7_Building-Detection-MaskRCNN-master\load_model.py", line 6, in
loaded_model=load_model('D:/python/building_detection/7_Building-Detection-MaskRCNN-master/Building-Detection.h5')

File "C:\Users\rajak\anaconda3\envs\mrcnn_building\lib\site-packages\keras\engine\saving.py", line 492, in load_wrapper
return load_function(*args, **kwargs)

File "C:\Users\rajak\anaconda3\envs\mrcnn_building\lib\site-packages\keras\engine\saving.py", line 584, in load_model
model = _deserialize_model(h5dict, custom_objects, compile)

File "C:\Users\rajak\anaconda3\envs\mrcnn_building\lib\site-packages\keras\engine\saving.py", line 270, in _deserialize_model
model_config = h5dict['model_config']

File "C:\Users\rajak\anaconda3\envs\mrcnn_building\lib\site-packages\keras\utils\io_utils.py", line 318, in getitem
raise ValueError('Cannot create group in read-only mode.')

ValueError: Cannot create group in read-only mode.


Could you please help me with using the pre-trained model and detect the building-footprints from a given test image? Please share a sample code for the same.

Awaiting your response.

Thank you.

How to rename the file

  1. What are the total files that need to be renamed?
  2. What are the rules for renaming? Can you give an example of how to rename it? (I followed the rules of RGB-PanSharpen_AOI_2_Vegas_imgg1.tif, RGB-PanSharpen_AOI_2_Vegas_imgg2.tif..... and buildings_AOI_2_Vegas_imgg1.geojson. When the buildings_AOI_2_Vegas_imgg2.geojson is extracted, there will be an error that does not match the actual mask.
  3. Is the file extracted by create_mask.py useful? I see that the mask image is not used in SpacenetTrain.py.
    Thank you for your help!
    The following is the interface output by train.py after I renamed it according to my method
    1
    2

Hocam Yardımınıza ihtiyacım var

Hocam merhabalar.Google Colab'da Yapı algılama modeli oluşturmak istiyorum ama veri boyutu nedeniyle yol alamıyorum bilgisayarıma Mask RCNN kuramıyorum gereksinimleri karşılamıyo ne yapabilirim

There is a problem that mAP is always calculated as 0.0.

I ran the SpaceNet_train.py file using the weights file you provided. (The learning step is omitted.)
However, unlike the code, random images are not displayed, and mAP is always calculated as 0.0.
Actually, I'm a beginner who just studied deep learning, so I can't figure out which part is wrong.
I am attaching the file(convert txt to py) I ran, so please tell me where the problem is.
Thank you always.

Configurations:
BACKBONE resnet50
BACKBONE_STRIDES [4, 8, 16, 32, 64]
BATCH_SIZE 1
BBOX_STD_DEV [0.1 0.1 0.2 0.2]
COMPUTE_BACKBONE_SHAPE None
DETECTION_MAX_INSTANCES 350
DETECTION_MIN_CONFIDENCE 0.7
DETECTION_NMS_THRESHOLD 0.3
FPN_CLASSIF_FC_LAYERS_SIZE 1024
GPU_COUNT 1
GRADIENT_CLIP_NORM 5.0
IMAGES_PER_GPU 1
IMAGE_CHANNEL_COUNT 3
IMAGE_MAX_DIM 640
IMAGE_META_SIZE 14
IMAGE_MIN_DIM 640
IMAGE_MIN_SCALE 0
IMAGE_RESIZE_MODE square
IMAGE_SHAPE [640 640 3]
LEARNING_MOMENTUM 0.9
LEARNING_RATE 0.001
LOSS_WEIGHTS {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'mrcnn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0}
MASK_POOL_SIZE 14
MASK_SHAPE [28, 28]
MAX_GT_INSTANCES 250
MEAN_PIXEL [123.7 116.8 103.9]
MINI_MASK_SHAPE (56, 56)
NAME SpaceNet
NUM_CLASSES 2
POOL_SIZE 7
POST_NMS_ROIS_INFERENCE 1000
POST_NMS_ROIS_TRAINING 2000
PRE_NMS_LIMIT 6000
ROI_POSITIVE_RATIO 0.33
RPN_ANCHOR_RATIOS [0.25, 1, 4]
RPN_ANCHOR_SCALES (8, 16, 32, 64, 128)
RPN_ANCHOR_STRIDE 1
RPN_BBOX_STD_DEV [0.1 0.1 0.2 0.2]
RPN_NMS_THRESHOLD 0.7
RPN_TRAIN_ANCHORS_PER_IMAGE 256
STEPS_PER_EPOCH 500
TOP_DOWN_PYRAMID_SIZE 256
TRAIN_BN False
TRAIN_ROIS_PER_IMAGE 32
USE_MINI_MASK True
USE_RPN_ROIS True
VALIDATION_STEPS 50
WEIGHT_DECAY 0.0001

1165
C:\Users\Seo\anaconda3\envs\mrcnn\lib\site-packages\mask_rcnn-2.1-py3.6.egg\mrcnn\visualize.py:56: UserWarning:

Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

1336
788
737
WARNING:tensorflow:From C:\Users\Seo\anaconda3\envs\mrcnn\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be
removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From C:\Users\Seo\anaconda3\envs\mrcnn\lib\site-packages\keras\backend\tensorflow_backend.py:1154: calling reduce_max_v1 (from tensorflow.python.ops.math_ops) with keep_dims is deprecate
d and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNING:tensorflow:From C:\Users\Seo\anaconda3\envs\mrcnn\lib\site-packages\keras\backend\tensorflow_backend.py:1188: calling reduce_sum_v1 (from tensorflow.python.ops.math_ops) with keep_dims is deprecate
d and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNING:tensorflow:From C:\Users\Seo\anaconda3\envs\mrcnn\lib\site-packages\mask_rcnn-2.1-py3.6.egg\mrcnn\model.py:772: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a
future version.
Instructions for updating:
Use tf.cast instead.
Loading weights from D:\mask_rcnn_spacenet_0151.h5
2021-11-09 01:06:42.125108: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-11-09 01:06:42.267542: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties:
name: GeForce RTX 3060 Ti major: 8 minor: 6 memoryClockRate(GHz): 1.695
pciBusID: 0000:01:00.0
totalMemory: 8.00GiB freeMemory: 6.99GiB
2021-11-09 01:06:42.268127: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2021-11-09 01:10:02.188573: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-11-09 01:10:02.188862: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0
2021-11-09 01:10:02.189157: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N
2021-11-09 01:10:02.189519: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6714 MB memory) -> physical GPU (device: 0,
name: GeForce RTX 3060 Ti, pci bus id: 0000:01:00.0, compute capability: 8.6)
original_image shape: (640, 640, 3) min: 6.00000 max: 250.00000 uint8
image_meta shape: (14,) min: 0.00000 max: 650.00000 float64
gt_class_id shape: (0,) min: max: int32
gt_bbox shape: (0, 4) min: max: int32
gt_mask shape: (640, 640, 0) min: max: bool

*** No instances to display ***

C:\Users\Seo\anaconda3\envs\mrcnn\lib\site-packages\mask_rcnn-2.1-py3.6.egg\mrcnn\visualize.py:167: UserWarning:

Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

Processing 1 images
image shape: (640, 640, 3) min: 6.00000 max: 250.00000 uint8
molded_images shape: (1, 640, 640, 3) min: -117.70000 max: 133.20000 float64
image_metas shape: (1, 14) min: 0.00000 max: 640.00000 int32
anchors shape: (1, 102300, 4) min: -0.20031 max: 1.10016 float32
2021-11-09 01:10:04.638200: I tensorflow/stream_executor/dso_loader.cc:152] successfully opened CUDA library cublas64_100.dll locally

*** No instances to display ***

mAP: 0.
SpaceNet_train_modified.txt
0

Train Dataset and panSharpen1

hello Sir. Can you post the necessary files to run the application? also the python file where you created your model? I need to be able to get results like; F1 Score, Validation date, binary_accuracy, loss

Cannot use pre-trained file cannot be used in matterport/Mask-RCNN

It would be appreciated if someone clarify how to implement building detection using pre-trained file and matterport's Mask-RCNN.

Before getting into the building detection, I could run "demo.ipynb" in "sample" folder in matterport's repository and detect objects using some my own images.

Now, I am trying to change the original pre-trained file (mask_rcnn_coco.h5) to yours (mask_rcnn_spacenet_0151.h5) to detect buildings from satellite images.

Here I attached the demo_building.ipynb which I slightly modified to load your pre-trained model.
The changes are really limited:

demo_building.txt
As .ipynb file was not accepted, please change the extension from .txt to .ipynb.

Changing pre-trained file
1

As I am not sure of the class_names in the replaced pre-trained file, currently I just commented out class_names.
Perhaps it may require some updates but I have no idea on this.
2

However, as a result, an error occurs when I run the following script as attached in the file error.txt.
3

error.txt

It would be highly appreciated if you could suggest any corrections to run the model and detect the footprints appropriately. As I am quite new in this field, please forgive me if I miss some basics.

Thank you in advance for your support.

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.