Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kwea123/aa40fd240fcef284e70f9fdae446cd6a to your computer and use it in GitHub Desktop.

Select an option

Save kwea123/aa40fd240fcef284e70f9fdae446cd6a to your computer and use it in GitHub Desktop.
example code to get depth prediction for `depth from video in the wild` https://github.com/google-research/google-research/tree/master/depth_from_video_in_the_wild
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning: To use the exr data format, please install the OpenEXR package following the instructions detailed in the README at github.com/tensorflow/graphics.\n",
"Warning: To use the threejs_vizualization, please install the colabtools package following the instructions detailed in the README at github.com/tensorflow/graphics.\n",
"WARNING: Logging before flag parsing goes to stderr.\n",
"W1024 04:25:34.665361 140562096183040 lazy_loader.py:50] \n",
"The TensorFlow contrib module will not be included in TensorFlow 2.0.\n",
"For more information, please see:\n",
" * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md\n",
" * https://github.com/tensorflow/addons\n",
" * https://github.com/tensorflow/io (for I/O related ops)\n",
"If you depend on functionality not listed there, please file an issue.\n",
"\n"
]
}
],
"source": [
"import numpy as np\n",
"import tensorflow as tf\n",
"import model"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"W1024 04:25:35.306735 140562096183040 deprecation_wrapper.py:119] From /home/ubuntu/workspace/google-research/depth_from_video_in_the_wild/model.py:377: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.\n",
"\n",
"W1024 04:25:35.307401 140562096183040 deprecation_wrapper.py:119] From /home/ubuntu/workspace/google-research/depth_from_video_in_the_wild/model.py:377: The name tf.AUTO_REUSE is deprecated. Please use tf.compat.v1.AUTO_REUSE instead.\n",
"\n",
"W1024 04:25:35.360530 140562096183040 deprecation_wrapper.py:119] From /home/ubuntu/workspace/google-research/depth_from_video_in_the_wild/model.py:378: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.\n",
"\n",
"W1024 04:25:35.441872 140562096183040 deprecation_wrapper.py:119] From /home/ubuntu/workspace/google-research/depth_from_video_in_the_wild/depth_prediction_net.py:281: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.\n",
"\n",
"W1024 04:25:35.460598 140562096183040 deprecation_wrapper.py:119] From /home/ubuntu/workspace/google-research/depth_from_video_in_the_wild/depth_prediction_net.py:285: The name tf.get_collection is deprecated. Please use tf.compat.v1.get_collection instead.\n",
"\n",
"W1024 04:25:35.514074 140562096183040 deprecation_wrapper.py:119] From /home/ubuntu/workspace/google-research/depth_from_video_in_the_wild/depth_prediction_net.py:58: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.\n",
"\n",
"W1024 04:25:35.550806 140562096183040 deprecation.py:323] From /home/ubuntu/workspace/google-research/depth_from_video_in_the_wild/depth_prediction_net.py:293: batch_normalization (from tensorflow.python.layers.normalization) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use keras.layers.BatchNormalization instead. In particular, `tf.control_dependencies(tf.GraphKeys.UPDATE_OPS)` should not be used (consult the `tf.keras.layers.batch_normalization` documentation).\n",
"W1024 04:25:36.732197 140562096183040 deprecation_wrapper.py:119] From /home/ubuntu/workspace/google-research/depth_from_video_in_the_wild/motion_prediction_net.py:198: The name tf.image.resize_bilinear is deprecated. Please use tf.compat.v1.image.resize_bilinear instead.\n",
"\n",
"W1024 04:25:37.096778 140562096183040 deprecation.py:323] From /home/ubuntu/workspace/google-research/depth_from_video_in_the_wild/motion_prediction_net.py:54: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use `tf.cast` instead.\n"
]
}
],
"source": [
"train_model = model.Model(img_height=None, img_width=None, batch_size=None, is_training=False)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"W1024 04:25:42.981806 140562096183040 deprecation.py:323] From /home/ubuntu/anaconda3/envs/keras_p36/lib/python3.6/site-packages/tensorflow/python/training/saver.py:1276: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use standard file APIs to check for files with this prefix.\n"
]
}
],
"source": [
"sess = tf.Session()\n",
"saver = tf.train.Saver()\n",
"saver.restore(sess, 'cityscapes_kitti_learned_intrinsics/model-1000977')\n",
"# saver.restore(sess, 'kitti_learned_intrinsics/model-248900')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7fd5d596dc88>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
@kwea123
Copy link
Author

kwea123 commented Oct 23, 2019

Put this notebook under google-research/depth_from_video_in_the_wild/.
Download the model weights from original repo.
You need two additional steps before running this notebook.

  1. remove all the from depth_from_video_in_the_wild in the imports.
  2. comment out self.global_step = ... in line 88 in model.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment