Estimating Street Safeness after an Earthquake with Computer Vision And Route Planning

Estimating Street Safeness after an Earthquake with Computer Vision And Route Planning

Is it possible to estimate with minimum expert knowledge if your street will be safer than others when an earthquake occurs?


We answered how to estimate the safest route after an earthquake with computer vision and route management.


The problem

The last devastating earthquake in Turkey occurred in 1999 (>7 on the Richter scale) around 150–200 kilometers from Istanbul. Scientists believe that this time the earthquake will burst directly in the city and the magnitude is predicted to be similar.

The main motivation behind this AI project hosted by Impacthub Istanbul is to optimize the Aftermath Management of Earthquake with AI and route planning.


Children need their parents!

After kicking off the project and brainstorming with the hosts, collaborators, and the Omdena team about how to better prepare the city of Istanbul for an upcoming disaster, we spotted a problem quite simple but at the same time really important for families: get reunited ASAP in earthquake aftermath!

Our target was set to provide safe and fast route planning for families, considering not only time factors but also broken bridges, landing debris, and other obstacles usually found in these scenarios.


Fatih, one of the most popular and crowded districts in Istanbul. Source: Mapbox API



We resorted to working on two tasks: creating a risk heatmap that would depict how dangerous is a particular area on the map, and a path-finding algorithm providing the safest and shortest path from A to B. The latter algorithm would rely on the previous heatmap to estimate safeness.

Challenge started! Deep Learning for Earthquake management by the use of Computer Vision and Route Management.


Source: Unsplash @loic


By this time, we optimistically trusted in open data to successfully address our problem. However, we realized soon that data describing buildings quality, soil composition, as well as pre and post-disaster imagery, were complex to model, integrate, when possible to find.

Bridges over streets, buildings height, 1000 types of soil, and eventually, interaction among all of them… Too many factors to control! So we just focused on delivering something more approximated.


Computer Vision and Deep Learning is the answer for Earthquake management

The question was: how to accurately estimate street safeness during any Earthquake in Istanbul without such a myriad of data? What if we could roughly estimate path safeness by embracing distance-to-buildings as a safety proxy. The farther the buildings the safer the pathway.

For that crazy idea, firstly we needed buildings footprints laid on the map. Some people suggested borrowing buildings footprints from Open Street Map, one of the most popular open-source map providers. However, we noticed soon Open Street Map, though quite complete, has some blank areas in terms of buildings metadata which were relevant for our task. Footprints were also inaccurately laid out on the map sometimes.


Haznedar area (Istanbul). Source: Satellite image from Google Maps.


Haznedar area too, but few footprints are shown. Blue boxes depict building footprints. Source: OpenStreetMap.


A big problem regarding the occurrence of any Earthquake and their effects on the population, and we have Computer Vision here to the rescue! Using Deep Learning, we could rely on satellite imagery to detect and then, estimated closeness from pathways to them.

The next stone on the road was to obtain high-resolution imagery of Istanbul. With enough resolution to allow an ML model locates building footprints in the map as a standard-visually-agile human does. Likewise, we would also need some annotated footprints on these images so that our model can gracefully train.



First step: Building a detection model with PyTorch and


SpaceNet dataset covering the area for Rio de Janeiro. Source:


Instead of labeling hundreds of square meters manually, we trusted on SpaceNet (and in particular, images for Rio de Janeiro) as our annotated data provider. This dataset contains high-resolution satellite images and building footprints, nicely pre-processed and organized which were used in a recent competition.

The modeling phase was really smooth thanks to software.

We used a Dynamic Unit model with an ImageNet pre-trained resnet34 encoder as a starting point for our model. This state-of-the-art architecture uses by default many advanced deep learning techniques, such as a one-cycle learning schedule or AdamW optimizer.

All these fancy advances in just a few lines of code.


fastai fancy plot advising you about learning rates.


We set up a balanced combination of Focal Loss and Dice Loss, and accuracy and dice metrics as performance evaluators. After several frozen and unfrozen steps in our model, we came up with good-enough predictions for the next step.

For more information about working with geospatial data and tools with, please refer to [1].



Where is my high-res imagery? Collecting Istanbul imagery for prediction.

Finding high-resolution imagery was the key to our model and at the same time a humongous stone hindering our path to victory.

For the training stage, it was easy to elude the manual annotation and data collection process thanks to SpaceNet, yet during prediction, obtaining high-res imagery for Istanbul was the only way.


Mapbox sexy logo


Thankfully, we stumble upon Mapbox and its easy-peasy almost-free download API which provides high-res slippy map tiles all over the world, and with different zoom levels. Slippy map tiles are 256 × 256 pixel files, described by x, y, z coordinates, where x and y represent 2D coordinates in the Mercator projection, and z the zoom level applied on earth globe. We chose a zoom level equal to 18 where each pixel links to real 0.596 meters.


Slippy map tiles on the Mercator projection (zoom level 2). Source:


As they mentioned on their webpage, they have a generous free tier that allows you to download up to 750,000 raster tiles a month for free. Enough for us as we wanted to grab tiles for a couple of districts.


Slippy raster tile at zoom level 18 (Fatih, Istanbul).



Time to predict: Create a mosaic-like your favorite painter

Once all required tiles were stealing space from my Google Drive, it was time to switch on our deep learning model and generate prediction footprints for each tile.


Model’s prediction for some tile in Rio: sometimes predictions looked better than actual footprints.


Then, we geo-referenced the tiles by translating from the Mercator coordinates to the latitude-longitude tuple (that used by mighty explorers). Geo-referencing tiles was a required step to create our prediction piece of art with GDAL software.

Python snippet to translate from Mercator coordinates to latitude and longitude.

Concretely, thecommand allows us to glue tiles by using embedded geo-coordinates in TIFF images. After some math, and computing time… voilà! Our high-res prediction map for the district is ready.


Raw predictions overlaid on Fatih. From a lower degree of building presence confidence (blue) to higher (yellow).



Inverse distance heatmap

Ok, I see my house but should I go through this street?

Building detection was not enough for our task. We should determine distance from a given position in the map to the closest building around so that a person in this place could know how safe is going to be to cross this street. The larger the distance the safer, remember?

The path-finding team would overlay the heatmap below on his graph-based schema and by intersecting graph edges (streets) with heatmap pixels (user positions), they could calculate the average distance for each pixel on the edge and thus obtaining a safeness estimation for each street. This would be our input when finding the best A-B path.


Distance-to-buildings heatmap in meters. Each pixel represents the distance from each point to the closest building predicted by our model. Blue means danger, yellow-green safeness.


But how to produce this picture from the raw prediction map? Clue: computing distance pixel-building for each tile independently is sub-optimal (narrow view), whereas the same computation on the entire mosaic will render as extremely expensive (3.5M of pixels multiplied thousands of buildings).

Working directly on the mosaic with a sliding window was the answer. Thus, for each pixel (x,y), a square matrix composed by (x-pad, y-pad, x+pad, y+pad) pixels from the original plot is created. Pad indicates the window side length in the number of pixels.


Pixel-wise distance computation. Orange is the point, blue is the closest building around. Side length = 100 pixels.


If a pixel belongs to some building, it returns zero. If not, return the minimum euclidean distance from the center point to the building’s pixels. This process along with NumPy optimizations was the key to mitigate the quadratic complexity beneath this computation.

Repeat the process for each pixel and the safeness map comes up.


Distance heatmap overlaid on the satellite image. Blue means danger, yellow-green safeness.



More about Omdena

Omdena is an innovation platform for building AI solutions to real-world problems through the power of bottom-up collaboration.

Using AI for Earthquake Response to Unite Families

Using AI for Earthquake Response to Unite Families

From a broad problem statement to a functional AI prototype in only two months to unite families in the aftermath of an earthquake.

Article written by Laura Clark Murray.


The Issue

Since the devastating 1999 earthquake in Istanbul that killed more than 18,000 people and left half a million homeless, experts have been warning about the need to prepare for another major earthquake. 

Late in 2019, a group of changemakers in the heart of Istanbul were looking to embark on a new project, in which they could apply innovative AI technology to solve a major issue for their local community. Well aware of the predictions that a major quake could hit at any time, these members of Impact Hub Istanbul, part of a global community focused on social innovation, decided to concentrate on response efforts in the immediate aftermath of an earthquake.


Earthquake response — that’s a broad problem.

Impact Hub Istanbul pulled in Omdena for our proven expertise in quickly transforming vague problem definitions into well-defined AI use cases. Omdena is a global platform where AI experts, engaged citizens and aspiring data scientists from diverse backgrounds collaborate to build AI-based solutions to humanity’s toughest problems. In our eight-week challenges, a community of 40 to 50 collaborators from around the world delivers deployable solutions using real-world data. 

You can learn more about Omdena’s innovative approach to building AI solutions through global collaboration here. Our partners include the UN, non-profit organizations and private corporations. In less than a year since our founding, over 700 AI enthusiasts from 70 countries have come together on Omdena challenges to solve social problems related to hunger, PTSD, sexual harassment, gang violence, wildfire prevention, and energy poverty

With the Omdena collaborators on board, the team considered the human experience of surviving an earthquake. They recognized a simple but significant dilemma. If family members are in different locations when an earthquake hits, as is the case when children are at school and parents are at work, reuniting is their highest priority. And that can be a terrifying prospect when it’s unclear how to safely navigate a city amid damage and destruction.

Could an AI system be built, using machine learning techniques, that would provide safe and fast route planning to reunite families in the hours after an earthquake hits? 


Is machine learning applicable to this problem?

We find that the best way to know if machine learning can solve a problem is to get out of the lab. By brainstorming with a diverse group of collaborators who bring different perspectives and expertise, potential solutions to a problem emerge. Modeling these alternative approaches using real-world data tells us what works. 

Together with Impact Hub Istanbul, we explored many alternate strategies for route planning. It was clear that parents and children should take paths that are likely to be safe after an earthquake. However, we needed to define what “safe” means in this context and then find the data required to assess it.

Collaborator Nguyen Tran shares the internal debates about framing the problem in his article on the challenge. 

As is often the case in real-world situations, the ideal data didn’t exist. When we uncover data roadblocks — nonexistent, incomplete or inaccurate data —  we invent ways to get around them. The domain expertise of our partners and the creativity of our diverse collaborators come into play. Semih Boyaci, Co-Founder of Impact Hub Istanbul, sees the benefit of working with an inclusive team: “As different community members contribute to the solutions, a significant level of diversity is integrated into the solutions. This not only prevents potential errors in a timely manner but also brings a higher level of creativity to the challenge process.”  

Through this collaborative and iterative process, we are able to start with a vague question and quickly refine it to one that is clear and actionable. And in the process, build a solution.


A prototype points to the path forward.

The goal was to create a prototype to accurately predict and verify safe routes between schools, hospitals, workplaces, and homes in one region of Istanbul. Focusing on the city’s Fatih District, the team pulled together and crafted data on the buildings and streets and built a model that calculated a risk score for each section of the district. Using various algorithms, the model identifies the shortest and safest path between two locations.


Fatih, one of the most popular and crowded districts in Istanbul.


The pathfinder algorithm


You can learn more about the data science behind this project from collaborator Sergio Ramírez Gallego. 

Building a prototype is a low-risk way to assess the applicability of AI techniques to a broad problem area and establish a direction for further investment and resources. Collaborator David Tran shares, “In a span of two months, we’ve explored the boundaries of the solution space, navigated through the limitations in data availability and technical complexity, and arrived at a functional solution.”

With a proof-of-concept in-hand, Impact Hub Istanbul has defined a concrete way to have an impact on earthquake response in their city using AI. 


What’s next?

Just as the project wrapped up in the last weeks of January its relevance was underscored when a  6.7 magnitude earthquake shook eastern Turkey, tragically killing at least 30 people and injuring more than 1600 — further motivating the Impact Hub Istanbul team to turn the prototype into a deployable application that incorporates all the districts of Istanbul. Before the next earthquake hits. 

“The result of this stunning process with Omdena was an AI-powered tool that helps families reunite in case of an earthquake by calculating the shortest and safest roads. It was really incredible to witness the productivity level when a group of talented people comes together around common motivations to solve problems for the social good. I believe that this is the way of working that all companies need to achieve in order to work with new generations.”

Semih Boyaci, Co-Founder, Impact Hub Istanbul



About Omdena

A global platform where AI experts, engaged citizens, and aspiring data scientists collaborate in two-month AI challenges to solve humanity’s toughest problems.

Join our community.

Open Data and Artificial Intelligence to Predict The Safest Path After an Earthquake

Open Data and Artificial Intelligence to Predict The Safest Path After an Earthquake

Uniting families through Artificial Intelligence and Open Street Map data by finding safe routes in the aftermath of an earthquake.

Article written by Anju Mercian.

There has been a lot of research to predict earthquakes and how to increase safety during an earthquake. A question that has remained relatively unexplored is what happens after an earthquake? And how can Artificial Intelligence help?

The aftermath of an earthquake comes with a lot of challenges:

  • Trying to get to a safe spot
  • Organizing rescue missions
  • How do parents get to their kids at school?

The last question is a big issue to tackle, which we focused on in this challenge.

Scientists predict that there will be an earthquake in Istanbul in the near future but the exact date is difficult to identify since Istanbul resides on a fault line. This means there is a possibility of major destruction.

Keeping families together and safe is the number one priority.

The problem-to-be-solved was proposed by Impacthub Istanbul, which wanted to collaborate with Omdena to leverage their AI capabilities and community to move from a broad problem statement to a functional AI solution.

Here is a non-technical summary of the challenge. 

The data

We used data from Open Street Map (OSMNX). Also, we sourced data from Google maps to get 3D images of the buildings and roads and did the modeling using Unity.

Excerpt: 3D modeled representation of Istanbul using Unity

Excerpt: 3D modeled representation of Istanbul


Using Artificial Intelligence for earthquake response


  • Getting all the building coverage details for the district working with ‘Fatih’ district
  • Finding the width of streets
  • Identifying the buildings and width of streets to help us calculate the risk score. The more buildings and narrow streets the lesser the safety after an earthquake. Combing building coverage and street map we calculated the risk score.
  • Finding out whether districts are adjacent by querying the OSM database.
  • Mapping the streets
  • Deriving the risk score and the walking distance to the destination.
  • To get a path from source to the destination we used Dijkstra’s algorithm combined with Q learning to find the shortest path between source and destination.

How did we go about this?

We used all the data from OSMX; the latitude, longitude data, edges, nodes.

  • Calculate the building coverage and street width map
  • Using OSMNX data: Interpolate the Points making up the line. Extract lon_lat coordinates of such points. Use the generated dictionary to convert each point to x_y positions in Numpy Matrix. Use the generated dictionary to convert each point to x_y positions in Numpy Matrix. Extract numpy values of all the points making up this edge/Line. Aggregate these values by: min, max, mean, median. Return aggregated values
  • Calculate the risk scores based on the two factors building coverage and street width. Residential areas had a higher risk score so when they imposed on the heat map it should show that these areas are possibly not very safe after an earthquake.
  • Get the district to district adjacent to map out the streets and map the risk level for the streets in order to find the shortest path.
  • Use the Dijkstra algorithm to find the shortest path from source to destination.

Problems we faced

  • OSMNX is not very fast we had a lot of buffer issues so we have to move only the Istanbul data to AWS S3 to get better performance.
  • OSMNX doesn’t have building coverage data so we have to scrap geo data from google maps to process it through Unity to get the 3 D images of images.


The output


For a more technical understanding of the challenge check out this article.

How did I get involved in the challenge?

Neither I’m an expert in the aftermath management of an earthquake nor was I an expert on network analysis using Artificial Intelligence.

I had gotten to know of Omdena through a friend on Social Media.

I was inspired by their vision of Building AI for Good through a collaborative environment and wanted to be a part of their challenge.

This project was a great learning experience. I joined this challenge not knowing how to solve this problem but the collaborative learning environment made it possible.

I had an understanding that Artificial Intelligence and Machine Learning was a vast field, but this project gave me an opportunity to experience it first hand.

Collaborating with my teammates across timezones helped me to co-ordinate my schedule more effectively, as well as learn from diverse perspectives.

Thanks to a very supportive team.


About Omdena

A global platform where AI experts, engaged citizens, and aspiring data scientists collaborate in two-month AI challenges to solve humanity’s toughest problems.

Join our community.

ML for Good: Improving Safety in an Earthquake with Machine Learning

ML for Good: Improving Safety in an Earthquake with Machine Learning

How to use Machine Learning for identifying the safest route after an earthquake.

Article written by Nguyen Tran.

Close your eyes for a moment. Imagine a nice day like any other nice day. The Sun is shining on the sea, and birds are singing in the trees. Suddenly, the trees start to shake, and the chair you’re sitting on is also shaking. You look around and begin to notice the confusion on the faces of your colleagues transitioning to dread: an earthquake is happening.



Remembering the drills, you take refuge under the cover of your work desk as objects around you fall from their places onto the ground. You pray for your life and the lives of those you love.

Seconds feel like minutes, and minutes feel like hours.

But at last, it was over. You thank for your life, but you felt an overwhelming need to ask for more than just your own safety as a surge of anxiety takes hold of you: Are your families OK? Your mind fixates on one thing: You MUST get to them, and that takes priority over anything else.


The Problem: Reaching your family and loved ones

Well, you, the reader, are probably right in that the scenario above is a bit overly dramatic, but it is hard to overstate the level of distress natural disasters, such as an earthquake, can cause to people.

And all participants in the Istanbul Earthquake Challenge share a similar sense of urgency and seriousness in finding ways to improve the situation for the earthquake victims.

That’s why early on in the challenge, we decided to focus to apply machine learning for the aftermath of an earthquake.


Machine Learning: Earthquake prediction

Machine Learning: Earthquake prediction


The aftermath of the earthquake might see communication cut-off or made extra difficult, causing problems with coordination between family members. Roads might be damaged and/or blocked up by debris falling from buildings. Traveling in the post-earthquake scenario will be chaotic and dangerous, but it won’t deter people from trying to reach their loved ones.


Machine Learning for earthquake response

It took our community of collaborators a fair bit of meandering exploration and a few fierce internal debates to finally boil the problem down to three main components: a) the representation of riskiness, b) the path-finding component, and c) the integration of a) and b).


Quantifying riskiness



This part proved to be a tricky part from the very start. Many team members devoted much time into gathering data that might contain some information regarding riskiness in the aftermath of an earthquake. We looked into various types of heatmaps: soil-composition heatmap, elevation heatmap, population heatmap, seismic hazard map,… but we faced two problems here.

First is the problem of sparsity of data. The resolutions of the heatmaps are both low (meaning a single value maps over a very large area) — therefore resulting in low precision, and mismatched — thus forcing us to interpolate and introduce high level of uncertainty. Second is the problem of accurately modeling the level of risks. Not unlike trying to predict the earthquake itself, we could not find enough labeled data to comfortably make riskiness-prediction a supervised learning exercise. After a lot of persistence but fruitless efforts, we finally realized that this component of the problem needs a fresh approach that does not follow the well-trodden path of seismology.


Our breakthrough :  Building coverage

A breakthrough came when a small group of members discussed the idea of using something concrete as a proxy for the abstract idea of safeness (which is the inverse of the abstract concept of riskiness). Safeness is a much more intuitive concept to a human’s mind. Safeness is also deducible from the observable surrounding: After an earthquake, it’s safer to stick to larger roads, and it’s safer to keep to areas with open-air.


Performing Distance-Transform on street segmentation mask (above). The numeric result (below) can be used to calculate the average width of the streets.

And so, we arrived at the two proxies for safeness:

  • Density of building,
  • Width of road.

Areas with lower building density are safer areas, so paths that run through these areas should be less risky. Similarly, wide streets are safer streets, so paths that move along these streets are also less risky. Two task groups were quickly formed to collect satellite images of the city and extract from them street masks and building masks using two newly trained image segmentation models.

After this, distance-transformation is applied on the prediction mask, giving us a rasterized map in which each pixel represents either the distance from a nearby building (in other words, how open is the space) or the distance from the side edge of the road (after some data aggregation, the road’s width).

You can read more about the segmentation models here.


Building Density Heatmap for Fatih District. Blue-Cyan spectrum represents areas with clusters of buildings. Green-Yellow spectrum represents open areas with few buildings.

Building Density Heatmap for Fatih District. Blue-Cyan spectrum represents areas with clusters of buildings. Green-Yellow spectrum represents open areas with few buildings.


The Path-finding component

This part was a great deal more straight forward than the previous part. Path-finding is a very well-established and well-tuned area of Machine Learning.

So, very early into the challenge, multiple demos were uploaded, leveraging the existing graphs of streets and intersections made available by the Open Street Map project. The initial demos used randomly-generated dummy risk data and attempted to find path based on singular objective either minimizing length or minimizing risk. Q-learning, Dijkstra, and A-star were the algorithm used. Later, the Graph ML team also successfully looked into a Multi-objective path-finding algorithm based on A-star algorithm with some tweaks that check for Pareto efficiency on every search iteration.


Illustration for Pareto Efficiency. Rather than optimizing for either the single objective on Y-axis or the single objective on X-axis, we look for a collection of solutions that are compromises between the two objectives.


A problem arose when testing the algorithm on large graphs made of multiple city districts: computation time increased dramatically as the number of nodes and edges ballooned.

A solution was proposed to prune nodes and edges using a hierarchical approach to path-finding. Rather than ingesting the entire city graph, a helper algorithm finds a path on a district level; the district-to-district pathings are fed to another helper algorithm that looks for the path on a neighborhood level. On the last level is the street-level graph constructed at a much-reduced size compared to the non-hierarchical approach. The smaller graph, with fewer nodes and edges, ensures that computation time remains reasonable even in the case of finding a path across the entire city.


An illustration of the concept of Hierarchical Pathfinding. Compared to the low-level graph, the high-level graph is much simpler and could be calculated quickly. The result is used to construct the low-level graph ONLY in the relevant area, filtering out unnecessary parts of the low-level graph to help speed up computation time.


Integration: Machine Learning for earthquake response

A working solution needs to be more than the sum of its parts, and integration is the process of realizing that. During the final weeks of the project, we found ourselves with two components that are not obviously compatible. On the one hand, there’s the path-finding algorithm that runs on Open Street Map graphs; on the other, there’s the rasterized heatmap whose values are encoded on individual pixels. One deals with vectors and vectorized shapes that are meant to represent real-world objects regardless of scale, and the other deals with numeric values that are scale-dependent.

If you’re familiar with Graphic Design, imagine transferring selective pixel values from Photoshop outputs to a Illustrator output while maintaining the integrity of the vector file.

After many trials and errors, the team came up with a way to map both outputs onto a shared space, in the form of an algebraic matrix. Interpolations were made between vector coordinates to simulate the presence of a vector line while a Moving Average filter runs along said line to collect the values of nearby pixels. The aggregated value is then mapped to the corresponding street vector in the graph. And voila, we were able to encode the riskiness value from the heatmap to the OSM street graph.




From top to bottom: the OSM graph of streets and intersection of the area; the building density heatmap of the area; and the combined result.


The Results

Thanks to the flexibility of Google Colaboratory, we were able to create a demo notebook that allows the user to test out the solution.

The demo is limited to only one district in Istanbul at the moment, namely, district Fatih. Users can test on a single-case basis with one pair of FROM-TO addresses or upload a CSV file, select the FROM column and TO column, and have the algorithm do searches in bulk.

Check out this colab notebook.


Comparison of pathfind results. In absence of the safeness data, a pathfinder will attempt to look for a path that cuts across the city, going through many areas with dense buildings and small streets. With the help of the safeness data, the algorithm can opt for paths that are longer but go through safer areas.



In this project, we looked into reducing the risk of traveling after the event of an earthquake using suitable machine learning approaches. In the urban environment of Istanbul, we made the assumption that safety correlates with areas with low building density and safety correlates with wider roads and streets.

Using state-of-the-art image machine learning models, we were able to represent said assumptions in the forms of rasterized heatmaps. We were also able to integrate the heatmaps with existing street graphs made available by the Open Street Map project. The final result allows the user to find the safest path from one place to another that favors going through open areas on wide streets and roads.

More importantly, all of this work was done by a team of volunteer collaborators across the world. Yet in a span of two months, we’ve explored the boundaries of the solution space, navigated through the limitations in data availability and technical complexity, and arrived at a functional solution.

I am very proud of having been a part of this challenge and, personally, thoroughly convinced that collaboration done right can bring about amazing results.

Thank you, Omdena, for this opportunity to learn and make a real impact on the world!



About Omdena

A global platform where AI experts, engaged citizens, and aspiring data scientists collaborate in two-month AI challenges to solve humanity’s toughest problems.

Join our community.

Stay in touch via our newsletter.

Be notified (a few times a month) about top-notch articles, new real-world projects, and events with our community of changemakers.

Sign up here