UNDER DEVELOPMENT
https://www.youtube.com/watch?v=HuU53ivwpEA
This is the python3 version of Hourglass model used by megadepth implemented in tf Keras.
python3 inference_mega_tensorflow.py
input
output
our output
MegaDepth_Tensorflow. Using this model, you can convert RGB image into depth map. The original version is PyTorch, here we convert it to TensorFlow version so that someone can deploy it on edge device or mobile.
UNDER DEVELOPMENT
https://www.youtube.com/watch?v=HuU53ivwpEA
This is the python3 version of Hourglass model used by megadepth implemented in tf Keras.
python3 inference_mega_tensorflow.py
input
output
our output
I made the following steps to get a tflite model:
1. Froze session:
output_graph_def = tf.compat.v1.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(["module/div_1"] ) with tf.compat.v1.gfile.GFile("megadepth.pb", "wb") as f: f.write(output_graph_def.SerializeToString())
2. Converted inference graph to tflite:
`
def convert():
converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph(
graph_def_file='megadepth.pb',
input_arrays=['Placeholder'],
input_shapes={'Placeholder' : [1, 240, 320, 3]},
output_arrays=['module/div_1']
)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_model = converter.convert()
with open('model.tflite', 'wb') as f:
f.write(tflite_model)
`
3. Ran inference on Android using implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
I used the model which includes pre and post processing. No matter what image I give the model, it always produces the exact same gradient grayscale image, very similar (or maybe the same) as reported here: zhengqili/MegaDepth#8
You wrote that you successfully ran inference on both iOS and Android. What tflite version did you try it with?
Is there any chance you can provide CoreML exports so we can test it on mobile devices? Thanks.
I've been trying to apply inference_mega_tensorflow.py
to my own images. It works well, until I try to generate full-resolution depth maps.
The error can be reproduced even with the stock docs/demo.jpg
. I'm changing the following lines in the above file:
input_height = 240
input_width = 320
Changing this to 2316X3099
results in the following error:
File "inference_mega_tensorflow.py", line 214, in <module>
main()
File "inference_mega_tensorflow.py", line 114, in main
mega_out = build_mega_model(imag_pl)
File "inference_mega_tensorflow.py", line 72, in build_mega_model
prediction_1 = HourglassModel().fridaymodel(input_image_ph, is_training=False)
File "/home/xxxx/EclipseWorkspace1/MegaDepth_TensorFlow/src/hourglass_mega_tf_resize_bilinear_tflayer_prepost.py", line 202, in fridaymodel
conv2a = self.Channels4(conv1a_relu, is_training=is_training)
File "/home/xxxx/EclipseWorkspace1/MegaDepth_TensorFlow/src/hourglass_mega_tf_resize_bilinear_tflayer_prepost.py", line 159, in Channels4
conv4b = self.Channels3(conv3b, is_training=is_training)
File "/home/xxxx/EclipseWorkspace1/MegaDepth_TensorFlow/src/hourglass_mega_tf_resize_bilinear_tflayer_prepost.py", line 134, in Channels3
conv4b = self.Channels2(conv3b, is_training=is_training)
File "/home/xxxx/EclipseWorkspace1/MegaDepth_TensorFlow/src/hourglass_mega_tf_resize_bilinear_tflayer_prepost.py", line 114, in Channels2
conv4b = self.Channels1(conv3b, is_training=is_training)
File "/home/xxxx/EclipseWorkspace1/MegaDepth_TensorFlow/src/hourglass_mega_tf_resize_bilinear_tflayer_prepost.py", line 95, in Channels1
output = conv2a + uconv4b
File "/home/xxxx/.local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 1181, in binary_op_wrapper
raise e
File "/home/xxxx/.local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 1165, in binary_op_wrapper
return func(x, y, name=name)
File "/home/xxxx/.local/lib/python3.6/site-packages/tensorflow/python/util/dispatch.py", line 206, in wrapper
return target(*args, **kwargs)
File "/home/xxxx/.local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 1487, in _add_dispatch
return gen_math_ops.add_v2(x, y, name=name)
File "/home/xxxx/.local/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 482, in add_v2
"AddV2", x=x, y=y, name=name)
File "/home/xxxx/.local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 750, in _apply_op_helper
attrs=attr_protos, op_def=op_def)
File "/home/xxxx/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3539, in _create_op_internal
op_def=op_def)
File "/home/xxxx/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2019, in __init__
control_input_ops, op_def)
File "/home/xxxx/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1859, in _create_c_op
raise ValueError(str(e))
ValueError: Dimensions must be equal, but are 289 and 288 for '{{node module/3/0/0/3/0/0/3/0/1/3/add}} = AddV2[T=DT_FLOAT](module/3/0/0/3/0/0/3/0/1/3/0/0/1/concat, module/3/0/0/3/0/0/3/0/1/3/0/1/4/resize/ResizeNearestNeighbor)' with input shapes: [1,289,387,256], [1,288,386,256].
Curiously, I only get this error for certain image sizes. For example, I find that 2304X3072
works fine, whereas 2316X3099
results in the above error.
How do I remove the need to specify image size, so that I automatically get a depthmap in the exact same resolution as the input image?
Hi,
Thank you very much for your work. Is that possible for you to upload .pbtxt file as well? Since tensorflow have changed to 2.0 and our class use tf 2.0 as well. I just need that to convert your pretrained model in tf2.0. Thank you very much!
Hello,
can you share Tensorflow training code ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.