Giter Site home page Giter Site logo

laggiss / gentrinet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azarz/gentrinet

1.0 1.0 0.0 30.6 MB

Tutorials and sources to reproduce results obtained during my 2017 summer internship at uOttawa

Python 83.12% CSS 1.73% PHP 4.66% HTML 3.05% JavaScript 7.44%

gentrinet's Introduction

gentriNet

If you have any question, please open an issue and I'll try to answer as quickly as possible.

Installation

NB: if you are at uOttawa Department of Geography, Environment and Geomatics, all the required libraries are installed in the python evironment located at D:\Amaury\Anaconda3\

You will need a Python 3 environment with all standard libraries installed. I personally used Anaconda3, and it was my only Python envronment on the machine. CAUTION: When using pip, make sure it is using the pip.exe of the correct Python environment.

How to determine where your pip.exe is for Anaconda

Open a command prompt in windows by typing "cmd" in the search bar. In the command prompt type:

where conda

which on my computer returns C:\ProgramData\Anaconda3\Scripts\conda.exe. As such, in the open command prompt I would type

cd C:\ProgramData\Anaconda3\Scripts

and then

dir

which returns within the resulting list of files and folders you would see a program called pip.exe:

screenshot

So in this folder, IF you wanted to install a package for python called testpackage you would type:

pip install testpackage

GIST vectors

To process GIST vectors the way I did in the Python scripts you will find in this repository, you will need to install this implementation: https://github.com/azarz/lear-gist-python. The installation procedure is described in the README.md.

Google StreetView

The Google API usually doesn't need any installation, but since we want historical imagery, we use this module: https://github.com/robolyst/streetview.

In order to make it work properly in our case, there is a small change to apply to the init.py file. Change line 56

def panoids(lat, lon, closest=False, disp=False):

to

def panoids(lat, lon, closest=True, disp=False):

To use it, simply place the folder containing the __init__.py in the same directory as your script, and import it using the line

import streetview

GDAL/OGR

Install it using the wheel from http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal

Keras and tensorflow

To install most modules, is use pip.exe, be it through PyPi or through downloaded files. It is the case with Keras, the high-level deep-learning library I used to manipulate neural networks. https://github.com/fchollet/keras

I also used the tensorflow GPU backend. I recommand you start with installing this library.

Tensorflow GPU for Windows (Only compatible with NVIDIA GPUs with compute cabability of 3.0 or higher (https://developer.nvidia.com/cuda-gpus))

I found that the steps described in https://www.tensorflow.org/install/install\_windows to not be sufficent for the library to work, so I reccomend you follow these instead:

  • Install CUDA® Toolkit 8.0 after downloading the version corresponding to your OS here: https://developer.nvidia.com/cuda-downloads
    • When installing the Toolkit, include the installation of the associated drivers
    • Also make sure that the /bin directory installed along with CUDA is added to the PATH environment variable
  • Download cuDNN v5.1 AND cuDNN v6.0 (https://developer.nvidia.com/rdp/cudnn-download) and copy all files from both downloads in the /bin folder of CUDA
  • Download tensorflow_gpu‑1.1.0‑cp36‑cp36m‑win_amd64.whl from this page: http://www.lfd.uci.edu/~gohlke/pythonlibs/ (this page is extremely useful for Windows users codingin Python)
  • Ensure that you place the downloaded tensorflow_gpu‑1.1.0‑cp36‑cp36m‑win_amd64.whl in the Scripts\ folder of the anaconda installation. To determine where to put this file see above How to determine where your pip.exe is for Anaconda.
  • Run a command prompt to use pip.exe on that .whl file.
pip install tensorflow_gpu‑1.1.0‑cp36‑cp36m‑win_amd64.whl

Tensorflow should now be installed on your computer.

Keras

Now that tensorflow is installed (ensure you are in a command prompt and within the Scripts\ folder of the anaconda installation- to determine where to put this file see above How to determine where your pip.exe is for Anaconda), you can install Keras uning pip and PyPi

pip install keras

During the installation, you may have prompts that tell you Keras can't be installed because of missing libraries. If this happens, simply use pip to install these missing libraries.

pip install <missing library name>

IMPORTANT: In order to load and save model wieghts (see below), you'll also need to install h5py.

pip install h5py

Usage example:

Main results: Convolutional Neural Networks (CNN)

Most of the model training and classification was done on a server using a NVIDIA Tesla K80 GPUs. I advise you to use powerful GPUs with more than 10 GB of memory, or else the processings could take a very, very long time

If you are at the Department of Geography, Environment and Geomatics at uOttawa, the set of images is already present on the server in the D:\Amaury\Desktop folder, under the ottawa_image_db directory, so do not bother spending several days downloading the StreetView imagery of Ottawa! (yes, this Desktop folder is a bit messy...)

Scripts to use: gentriNetConvServer2.py, gentriMap_allImages.py, to_positives.py

Get a .txt file filled with lines like this:

path/to/img1.jpg path/to/img2.jpg 0
path/to/img2.jpg path/to/img3.jpg 1

with 0 meaning no gentrification between the first and second image and 1 meaning the opposite.

Rename this file as retrain.txt and place it in the same directory as gentriNetConvServer2.py You should edit the gentriNetConvServer2.py lines corresponding to learning rates, number of iterations etc. according to your needs. Make sure that the last lines are uncommented so the model is saved after you train it for several days...

In a more general way, you should read the script files and commentary to understand the way they work before using them

To run the file on the Geography Depatment server, open a command prompt, and type this series of commands:

D:

cd D:\Amaury\Desktop\

D:\Amaury\Anaconda3\python.exe

[Python shell launches]

>>> exec(open("./gentriNetConvServer2.py").read())

Processing can take up to several days, even on a Tesla K80.

Once the model is saved, you can import it to classify your large set of images using gentriMap_allImages.py. You first have to edit the lines to make sure the right model is imported. Use this occasion to read the whole script and make sure it does what you think it does. To run it, if you are in the same command prompt window just type exec(open("./gentriMap_allImages.py").read())

CAUTION: you might have a Out Of Memory error (or similar one) if you do too much operations without closing the command prompt window. Workarounds are: close the current cmd window and open another one OR in the "with tf.device('/gpu:x'):" line of the script you want to run, modify the gpu index (0, 1, 2 or 3 instead of x)

Processing can take up to 30 hours, even on a Tesla K80.

The output of the classification is a set of 64 files corresponding to the classification results. In order to extract only the positive ones (which are the ones we're interested in) and fuse them in a single file, use the to_positives.py script. The functions you should use are res2pos_multi() and multipos2singlepos(). Unfortunately, I hardcoded the paths I used on my computer so if you're using another one, maybe you'll have to change them.

The resulting file ("positives_0-63.txt" by default) is a concatenation of all the positives detected by the model. You can load it in any GIS (I used QGIS) with the fist field as Y coordinates and second field as X coordinates in WGS84.

I personnaly had way to many false positives on my first go, these are the steps I followed to try and overcome this problem: https://github.com/azarz/gentriNet/blob/master/Iterative_models.md

Suggestions to improve the results

https://github.com/azarz/gentriNet/blob/master/suggestions.md

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.