Git Product home page Git Product logo

pix2depth's Introduction

No Maintenance Intended

Pix2Depth - Depth Map Estimation from Monocular Image

Update

I was not able to add the weights to the repository. I've created a drive and I'm adding the weights along with some images.

  • model - Weights from the experiment
  • src/model - Result of running the model on a sample image.

Weights and Results

Description

Estimating depth information from stereo images is easy, but does the same work for monocular images? We did all the heavylifting so you don't have to do it. We have explored several methods to extract depth from monocular images. Pix2Depth is a culmination of things we've learnt thus far.

Pix2Depth uses several strategies to extract depth from RGB images. Of all the strategies used, Pix2pix and CycleGAN give the best results. Pix2Depth is trained on the NYU Depth Dataset. Pix2Depth is also trained to predict RGB images from depth map.

The web demo for Pix2Depth can be found here

The web demo has three sections:

  • Pix2Depth - Using the models specified, give Pix2Depth an image and it will try to estimate the depth map.
  • Depth2Pix - From the Models given, Input a depth map and Pix2Depth will predict the estimated colour for the image.
  • Portrait Mode ( work in progress) - After obtaining the depth map, Pix2Depth uses the depth map to blur the background, so objects closer to the camera appear sharper while the background is blurred. This tries to emulate a potrait mode in smartphones without actually using stereo images.

Dataset

The dataset for this repo can be downloaded here.

Place the downloaded file in the folder data/

For the lazy: run download_nyu_dataset.sh to automatically download the dataset. Run save_all_images.py to store the images in seperate folders.

Required Packages

  • Keras
  • Flask
  • opencv
  • h5py
  • PIL
  • numpy

Running and evaluating

Configurations

CONFIG = {
        'development': False,
        'host': [host],
        'port': [port_number],
        'pix2depth':{
                'first_option':'pix2pix',
                'second_option':'CycleGAN',
                'third_option':'CNN',
        },
        'depth2pix':{
                'first_option':'pix2pix',
                'second_option':'CycleGAN',
                'third_option':'MSCNN'
        },
        'portrait':{
                'first_option': 'pix2pix',
                'second_option': 'CycleGAN',
                'third_option': 'CNN'
        }
}

Configure path to models

Loading the models stored in weights/ can be done inside main.py using model_list. This preloads all the models before inference hence saving a lot of time.

 model_list = {  
            'pix2depth':{ 
                'pix2pix' : load_model(),
                'CycleGAN':load_model(),
                'CNN': load_model(),
                },
            'depth2pix':{ 
                'pix2pix' : load_model(),
                'CycleGAN':load_model(),
                }
             }

Importing Models

Including Bootstrap Components

This demo requires Bootstrap (version 3). Bootstrap can be served to Flask from the static folder. The structure for storing the web-UI and images being displayed is as follows:

.
├── static
   ├── results
        └── results.jpg
        .
        .
        .
    └── uploads
        └── input.jpg
        .
        .
        .
   └── vendor
        └── bootstrap
                └── css
                └── js
        └── fonts
        └── jquery

Running the Application

python app.py

Examples

Output

  • main.py requires the path to the weights to load the model. The weights are stored in the folder weights/
  • The images are stored with the name of the model so it's easier to identify results. The generated images are stored in static/results/

Additional notes

pix2depth's People

Contributors

gautam678 avatar marziehlenjani avatar maximus009 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pix2depth's Issues

Where should I download these models?

Hello, thanks for developing such a amazing project. I have a question that where I should download these models in main.py. You've provided links to search for 'pix2pix', 'CycleGAN' and 'CNN', but I still can't find the corresponding name in either of these links.

Thanks,

model_list = {  
        'pix2depth':{ 
            'pix2pix' : load_model('weights/p2d_pix2pix.h5'),
            'CycleGAN':load_model('weights/p2d_cycle.h5'),
            'CNN': load_model('weights/p2d_cnn.h5'),
            },
        'depth2pix':{ 
            'pix2pix' : load_model('weights/d2p_pix2pix.h5'),
            'CycleGAN':load_model('weights/d2p_cycle.h5'),
            }
         }

import inf_cycle error

Hello, really thank you for the nice job. I tried to run app.py but got a 'No module named 'inf_cycle'' error. Is that a file you forgot to release? Thank you for your help~

Pretrain Model for CycleGAN

Hi, Thank you for the great work.

I'm wondering if it is possible that you could share the pretrain model for CycleGAN with .pth format? Due to the limited computational power, I can only train the model on Colab (it only accepts .pth files).

Any help is much appreciated:)

Server Error when running application

Perhaps I am doing something really silly here. Any help would be very much appreciated.

[2019-03-14 17:16:55,283] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "app.py", line 19, in main
    result_path = pix2depth(input_path,model)
  File "_path_/Pix2Depth/main.py", line 54, in pix2depth
    p1 = get_depth_map(x, loaded_model)
  File "_path_/Pix2Depth/main.py", line 111, in get_depth_map
    pred_dep = model.predict(np.array([input_image]), batch_size=1)[0]*255.
  File "/usr/local/lib/python2.7/site-packages/keras/engine/training.py", line 1164, in predict
    self._make_predict_function()
  File "/usr/local/lib/python2.7/site-packages/keras/engine/training.py", line 554, in _make_predict_function
    **kwargs)
  File "/usr/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 2744, in function
    return Function(inputs, outputs, updates=updates, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 2546, in __init__
    with tf.control_dependencies(self.outputs):
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 5028, in control_dependencies
    return get_default_graph().control_dependencies(control_inputs)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 4528, in control_dependencies
    c = self.as_graph_element(c)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3478, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3557, in _as_graph_element_locked
    raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("activation_9/Tanh:0", shape=(?, 256, 256, 3), dtype=float32) is not an element of this graph.
_hostname_ - - [14/Mar/2019 17:16:55] "POST / HTTP/1.1" 500 -

Depth units

Just trying to figure out the units here. Are the depth files basically unscaled depth or does it have real world units like meters?

Train models

Hello, first of all thanks for sharing this repository.

Because the weights are corrupt, I was trying to train the models, so I went through the code but it seems the actual models file (with model definitions and loading) is missing. Will you share this?

Thank you

run main

Hi, someone success to run the mail file
it shows to me this error:
capture d ecran 2018-12-09 a 12 23 27
If I understand correctly, i should create first or download a model.
How should I do that?
Someone did success and can help me?

Thank you very much

Training explanation

Hello,

Thanks for cool work. Could you please provide small instruction on how to reproduce results (i.e. using pix2pix or cyclegan)?

cannot load the model

When I try to run the main.py, it raises the following error message "raise IOError("SavedModel file does not exist at: %s/{%s|%s}" %" "OSError: SavedModel file does not exist at: ~/Downloads/Pix2Depth-master/weights/pix2pix_depth.h5/{saved_model.pbtxt|saved_model.pb}". Thank you for your help.

Unable to open file in weights

Hi! I'd like to try out your code, but I am getting stuck trying to open the pix2pix_depth.h5 file in weights, with the following error:

 File "/Pix2Depth/main.py", line 27, in <module>    
   'pix2pix' : load_model('/Pix2Depth/weights/pix2pix_depth.h5')
  File "/anaconda2/envs/py27base/lib/python2.7/site-packages/keras/models.py", line 237, in   load_model
    with h5py.File(filepath, mode='r') as f:
 File "/anaconda2/envs/py27base/lib/python2.7/site-packages/h5py/_hl/files.py", line 269, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
 File "/anaconda2/envs/py27base/lib/python2.7/site-packages/h5py/_hl/files.py", line 99, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
 File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
 File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
 File "h5py/h5f.pyx", line 78, in h5py.h5f.open
 IOError: Unable to open file (file signature not found)

Any suggestions for how to fix it would be appreciated!

Web demo returns "Connection refused"

Whenever I try to access the link for your demo, my browser (Google Chrome, Microsoft Edge, Tor Browser) returns this error:

This site can’t be reached
128.143.63.199 refused to connect.
ERR_CONNECTION_REFUSED

Is this on my side or yours?

Cheers!

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.