From 8078863ff00ed2b40330c54985567928b3a755e5 Mon Sep 17 00:00:00 2001 From: khoa Date: Mon, 20 Mar 2023 02:48:50 +0000 Subject: [PATCH] update to run on TF2.11.* --- config_fern.txt | 2 +- environment.yml | 241 +++++++++++++++++++++++++++++++++++++++++--- run_nerf.py | 64 ++++++------ run_nerf_helpers.py | 2 +- 4 files changed, 265 insertions(+), 44 deletions(-) diff --git a/config_fern.txt b/config_fern.txt index a044d2b6..c1fb2a2d 100644 --- a/config_fern.txt +++ b/config_fern.txt @@ -1,6 +1,6 @@ expname = fern_test basedir = ./logs -datadir = ./data/nerf_llff_data/fern +datadir = /home/khoa/workspace/Data_set/NeRF_Data/nerf_llff_data/fern dataset_type = llff factor = 8 diff --git a/environment.yml b/environment.yml index 08c36069..d83190ad 100644 --- a/environment.yml +++ b/environment.yml @@ -1,15 +1,230 @@ -# To run: conda env create -f environment.yml -name: nerf +name: nerf_tf channels: - - conda-forge + - conda-forge + - defaults dependencies: - - python=3.7 - - pip - - cudatoolkit=10.0 - - tensorflow-gpu==1.15 - - numpy - - matplotlib - - imageio - - imageio-ffmpeg - - configargparse - - imagemagick + - _libgcc_mutex=0.1=conda_forge + - _openmp_mutex=4.5=2_gnu + - alsa-lib=1.2.8=h166bdaf_0 + - aom=3.5.0=h27087fc_0 + - atk-1.0=2.38.0=hd4edc92_1 + - attr=2.5.1=h166bdaf_1 + - brotli=1.0.9=h166bdaf_8 + - brotli-bin=1.0.9=h166bdaf_8 + - bzip2=1.0.8=h7f98852_4 + - ca-certificates=2022.12.7=ha878542_0 + - cairo=1.16.0=ha61ee94_1014 + - certifi=2022.12.7=pyhd8ed1ab_0 + - configargparse=1.5.3=pyhd8ed1ab_0 + - contourpy=1.0.7=py39h4b4f3f3_0 + - cudatoolkit=11.2.2=hbe64b41_11 + - cudnn=8.1.0.77=h90431f1_0 + - cycler=0.11.0=pyhd8ed1ab_0 + - dbus=1.13.6=h5008d03_3 + - expat=2.5.0=h27087fc_0 + - ffmpeg=5.1.2=gpl_h8dda1f0_106 + - fftw=3.3.10=nompi_hf0379b8_106 + - font-ttf-dejavu-sans-mono=2.37=hab24e00_0 + - font-ttf-inconsolata=3.000=h77eed37_0 + - font-ttf-source-code-pro=2.038=h77eed37_0 + - font-ttf-ubuntu=0.83=hab24e00_0 + - fontconfig=2.14.2=h14ed4e7_0 + - fonts-conda-ecosystem=1=0 + - fonts-conda-forge=1=0 + - fonttools=4.39.2=py39h72bdee0_0 + - freetype=2.12.1=hca18f0e_1 + - fribidi=1.0.10=h36c2ea0_0 + - gdk-pixbuf=2.42.10=h05c8ddd_0 + - gettext=0.21.1=h27087fc_0 + - ghostscript=9.54.0=h27087fc_2 + - giflib=5.2.1=h0b41bf4_3 + - glib=2.74.1=h6239696_1 + - glib-tools=2.74.1=h6239696_1 + - gmp=6.2.1=h58526e2_0 + - gnutls=3.7.8=hf3e180e_0 + - graphite2=1.3.13=h58526e2_1001 + - graphviz=6.0.2=h99bc08f_0 + - gst-plugins-base=1.22.0=h4243ec0_2 + - gstreamer=1.22.0=h25f0c4b_2 + - gstreamer-orc=0.4.33=h166bdaf_0 + - gtk2=2.24.33=h90689f9_2 + - gts=0.7.6=h64030ff_2 + - harfbuzz=6.0.0=h8e241bc_0 + - icu=70.1=h27087fc_0 + - imageio=2.26.0=pyh24c5eb1_0 + - imageio-ffmpeg=0.4.8=pyhd8ed1ab_0 + - imagemagick=7.1.1_3=pl5321h0dc3a92_0 + - importlib-resources=5.12.0=pyhd8ed1ab_0 + - importlib_resources=5.12.0=pyhd8ed1ab_0 + - jack=1.9.22=h11f4161_0 + - jbig=2.1=h7f98852_2003 + - jpeg=9e=h0b41bf4_3 + - keyutils=1.6.1=h166bdaf_0 + - kiwisolver=1.4.4=py39hf939315_1 + - krb5=1.20.1=h81ceb04_0 + - lame=3.100=h166bdaf_1003 + - lcms2=2.15=hfd0df8a_0 + - ld_impl_linux-64=2.40=h41732ed_0 + - lerc=4.0.0=h27087fc_0 + - libblas=3.9.0=16_linux64_openblas + - libbrotlicommon=1.0.9=h166bdaf_8 + - libbrotlidec=1.0.9=h166bdaf_8 + - libbrotlienc=1.0.9=h166bdaf_8 + - libcap=2.66=ha37c62d_0 + - libcblas=3.9.0=16_linux64_openblas + - libclang13=15.0.7=default_h3e3d535_1 + - libcups=2.3.3=h36d4200_3 + - libdb=6.2.32=h9c3ff4c_0 + - libdeflate=1.17=h0b41bf4_0 + - libdrm=2.4.114=h166bdaf_0 + - libedit=3.1.20191231=he28a2e2_2 + - libevent=2.1.10=h28343ad_4 + - libffi=3.4.2=h7f98852_5 + - libflac=1.4.2=h27087fc_0 + - libgcc-ng=12.2.0=h65d4601_19 + - libgcrypt=1.10.1=h166bdaf_0 + - libgd=2.3.3=h5aea950_4 + - libgfortran-ng=12.2.0=h69a702a_19 + - libgfortran5=12.2.0=h337968e_19 + - libglib=2.74.1=h606061b_1 + - libgomp=12.2.0=h65d4601_19 + - libgpg-error=1.46=h620e276_0 + - libiconv=1.17=h166bdaf_0 + - libidn2=2.3.4=h166bdaf_0 + - liblapack=3.9.0=16_linux64_openblas + - libllvm15=15.0.7=hadd5161_1 + - libnsl=2.0.0=h7f98852_0 + - libogg=1.3.4=h7f98852_1 + - libopenblas=0.3.21=pthreads_h78a6416_3 + - libopus=1.3.1=h7f98852_1 + - libpciaccess=0.17=h166bdaf_0 + - libpng=1.6.39=h753d276_0 + - libpq=15.2=hb675445_0 + - librsvg=2.54.4=h7abd40a_0 + - libsndfile=1.2.0=hb75c966_0 + - libsqlite=3.40.0=h753d276_0 + - libstdcxx-ng=12.2.0=h46fd767_19 + - libsystemd0=252=h2a991cd_0 + - libtasn1=4.19.0=h166bdaf_0 + - libtiff=4.5.0=h6adf6a1_2 + - libtool=2.4.7=h27087fc_0 + - libudev1=253=h0b41bf4_0 + - libunistring=0.9.10=h7f98852_0 + - libuuid=2.32.1=h7f98852_1000 + - libva=2.17.0=h0b41bf4_0 + - libvorbis=1.3.7=h9c3ff4c_0 + - libvpx=1.11.0=h9c3ff4c_3 + - libwebp=1.2.4=h1daa5a0_1 + - libwebp-base=1.2.4=h166bdaf_0 + - libxcb=1.13=h7f98852_1004 + - libxkbcommon=1.5.0=h79f4944_1 + - libxml2=2.10.3=hca2bb57_3 + - libzlib=1.2.13=h166bdaf_4 + - lz4-c=1.9.4=hcb278e6_0 + - matplotlib=3.7.1=py39hf3d152e_0 + - matplotlib-base=3.7.1=py39he190548_0 + - mpg123=1.31.2=hcb278e6_0 + - munkres=1.1.4=pyh9f0ad1d_0 + - mysql-common=8.0.32=ha901b37_0 + - mysql-libs=8.0.32=hd7da12d_0 + - ncurses=6.3=h27087fc_1 + - nettle=3.8.1=hc379101_1 + - nspr=4.35=h27087fc_0 + - nss=3.89=he45b914_0 + - numpy=1.24.2=py39h7360e5f_0 + - openh264=2.3.1=hcb278e6_2 + - openjpeg=2.5.0=hfec8fc6_2 + - openssl=3.1.0=h0b41bf4_0 + - p11-kit=0.24.1=hc5aa10d_0 + - packaging=23.0=pyhd8ed1ab_0 + - pango=1.50.14=hd33c08f_0 + - pcre2=10.40=hc3806b6_0 + - perl=5.32.1=2_h7f98852_perl5 + - pillow=9.4.0=py39h2320bf1_1 + - pip=23.0.1=pyhd8ed1ab_0 + - pixman=0.40.0=h36c2ea0_0 + - pkg-config=0.29.2=h36c2ea0_1008 + - ply=3.11=py_1 + - pthread-stubs=0.4=h36c2ea0_1001 + - pulseaudio=16.1=ha8d29e2_1 + - pyparsing=3.0.9=pyhd8ed1ab_0 + - pyqt=5.15.7=py39h5c7b992_3 + - pyqt5-sip=12.11.0=py39h227be39_3 + - python=3.9.16=h2782a2a_0_cpython + - python-dateutil=2.8.2=pyhd8ed1ab_0 + - python_abi=3.9=3_cp39 + - qt-main=5.15.8=h5d23da1_6 + - readline=8.1.2=h0f457ee_0 + - setuptools=67.6.0=pyhd8ed1ab_0 + - sip=6.7.7=py39h227be39_0 + - six=1.16.0=pyh6c4a22f_0 + - svt-av1=1.4.1=hcb278e6_0 + - tk=8.6.12=h27826a3_0 + - toml=0.10.2=pyhd8ed1ab_0 + - tornado=6.2=py39hb9d737c_1 + - tzdata=2022g=h191b570_0 + - unicodedata2=15.0.0=py39hb9d737c_0 + - wheel=0.40.0=pyhd8ed1ab_0 + - x264=1!164.3095=h166bdaf_2 + - x265=3.5=h924138e_3 + - xcb-util=0.4.0=h166bdaf_0 + - xcb-util-image=0.4.0=h166bdaf_0 + - xcb-util-keysyms=0.4.0=h166bdaf_0 + - xcb-util-renderutil=0.3.9=h166bdaf_0 + - xcb-util-wm=0.4.1=h166bdaf_0 + - xkeyboard-config=2.38=h0b41bf4_0 + - xorg-fixesproto=5.0=h7f98852_1002 + - xorg-kbproto=1.0.7=h7f98852_1002 + - xorg-libice=1.0.10=h7f98852_0 + - xorg-libsm=1.2.3=hd9c2040_1000 + - xorg-libx11=1.8.4=h0b41bf4_0 + - xorg-libxau=1.0.9=h7f98852_0 + - xorg-libxdmcp=1.1.3=h7f98852_0 + - xorg-libxext=1.3.4=h0b41bf4_2 + - xorg-libxfixes=5.0.3=h7f98852_1004 + - xorg-libxrender=0.9.10=h7f98852_1003 + - xorg-libxt=1.2.1=h7f98852_2 + - xorg-renderproto=0.11.1=h7f98852_1002 + - xorg-xextproto=7.3.0=h0b41bf4_1003 + - xorg-xproto=7.0.31=h7f98852_1007 + - xz=5.2.6=h166bdaf_0 + - zipp=3.15.0=pyhd8ed1ab_0 + - zlib=1.2.13=h166bdaf_4 + - zstd=1.5.2=h3eb15da_6 + - pip: + - absl-py==1.4.0 + - astunparse==1.6.3 + - cachetools==5.3.0 + - charset-normalizer==3.1.0 + - flatbuffers==23.3.3 + - gast==0.4.0 + - google-auth==2.16.2 + - google-auth-oauthlib==0.4.6 + - google-pasta==0.2.0 + - grpcio==1.51.3 + - h5py==3.8.0 + - idna==3.4 + - importlib-metadata==6.1.0 + - keras==2.11.0 + - libclang==15.0.6.1 + - markdown==3.4.1 + - markupsafe==2.1.2 + - oauthlib==3.2.2 + - opt-einsum==3.3.0 + - protobuf==3.19.6 + - pyasn1==0.4.8 + - pyasn1-modules==0.2.8 + - requests==2.28.2 + - requests-oauthlib==1.3.1 + - rsa==4.9 + - tensorboard==2.11.2 + - tensorboard-data-server==0.6.1 + - tensorboard-plugin-wit==1.8.1 + - tensorflow==2.11.0 + - tensorflow-estimator==2.11.0 + - tensorflow-io-gcs-filesystem==0.31.0 + - termcolor==2.2.0 + - typing-extensions==4.5.0 + - urllib3==1.26.15 + - werkzeug==2.2.3 + - wrapt==1.15.0 diff --git a/run_nerf.py b/run_nerf.py index d75f051a..55bfe648 100644 --- a/run_nerf.py +++ b/run_nerf.py @@ -13,7 +13,6 @@ from load_deepvoxels import load_dv_data from load_blender import load_blender_data - tf.compat.v1.enable_eager_execution() @@ -667,6 +666,9 @@ def train(): with open(f, 'w') as file: file.write(open(args.config, 'r').read()) + testimgdir = os.path.join(basedir, expname, 'tboard_val_imgs') + os.makedirs(testimgdir, exist_ok=True) + # Create nerf model render_kwargs_train, render_kwargs_test, start, grad_vars, models = create_nerf( args) @@ -706,7 +708,7 @@ def train(): if args.lrate_decay > 0: lrate = tf.keras.optimizers.schedules.ExponentialDecay(lrate, decay_steps=args.lrate_decay * 1000, decay_rate=0.1) - optimizer = tf.keras.optimizers.Adam(lrate) + optimizer = tf.keras.optimizers.legacy.Adam(lrate) models['optimizer'] = optimizer global_step = tf.compat.v1.train.get_or_create_global_step() @@ -750,9 +752,9 @@ def train(): print('VAL views are', i_val) # Summary writers - writer = tf.contrib.summary.create_file_writer( + writer = tf.summary.create_file_writer( os.path.join(basedir, 'summaries', expname)) - writer.set_as_default() + # writer.set_as_default() for i in range(start, N_iters): time0 = time.time() @@ -835,7 +837,8 @@ def train(): def save_weights(net, prefix, i): path = os.path.join( basedir, expname, '{}_{:06d}.npy'.format(prefix, i)) - np.save(path, net.get_weights()) + # np.save(path, net.get_weights()) + np.save(path, np.asanyarray(net.get_weights(), object)) print('saved weights at', path) if i % args.i_weights == 0: @@ -875,12 +878,13 @@ def save_weights(net, prefix, i): print(expname, i, psnr.numpy(), loss.numpy(), global_step.numpy()) print('iter time {:.05f}'.format(dt)) - with tf.contrib.summary.record_summaries_every_n_global_steps(args.i_print): - tf.contrib.summary.scalar('loss', loss) - tf.contrib.summary.scalar('psnr', psnr) - tf.contrib.summary.histogram('tran', trans) + # with tf.summary.record_summaries_every_n_global_steps(args.i_print): + with writer.as_default(): + tf.summary.scalar('loss', loss, step=i) + tf.summary.scalar('psnr', psnr, step=i) + tf.summary.histogram('tran', trans, step=i) if args.N_importance > 0: - tf.contrib.summary.scalar('psnr0', psnr0) + tf.summary.scalar('psnr0', psnr0, step=i) if i % args.i_img == 0: @@ -895,31 +899,33 @@ def save_weights(net, prefix, i): psnr = mse2psnr(img2mse(rgb, target)) # Save out the validation image for Tensorboard-free monitoring - testimgdir = os.path.join(basedir, expname, 'tboard_val_imgs') - if i==0: - os.makedirs(testimgdir, exist_ok=True) - imageio.imwrite(os.path.join(testimgdir, '{:06d}.png'.format(i)), to8b(rgb)) - with tf.contrib.summary.record_summaries_every_n_global_steps(args.i_img): + # testimgdir = os.path.join(basedir, expname, 'tboard_val_imgs') + # if i==0: + # os.makedirs(testimgdir, exist_ok=True) + imageio.imwrite(os.path.join(testimgdir, '{:06d}.png'.format(i)), to8b(rgb)) - tf.contrib.summary.image('rgb', to8b(rgb)[tf.newaxis]) - tf.contrib.summary.image( - 'disp', disp[tf.newaxis, ..., tf.newaxis]) - tf.contrib.summary.image( - 'acc', acc[tf.newaxis, ..., tf.newaxis]) + # with tf.summary.record_summaries_every_n_global_steps(args.i_img): + with writer.as_default(): + tf.summary.image('rgb', to8b(rgb)[tf.newaxis], step=i) + tf.summary.image( + 'disp', disp[tf.newaxis, ..., tf.newaxis], step=i) + tf.summary.image( + 'acc', acc[tf.newaxis, ..., tf.newaxis], step=i) - tf.contrib.summary.scalar('psnr_holdout', psnr) - tf.contrib.summary.image('rgb_holdout', target[tf.newaxis]) + tf.summary.scalar('psnr_holdout', psnr, step=i) + tf.summary.image('rgb_holdout', target[tf.newaxis], step=i) if args.N_importance > 0: - with tf.contrib.summary.record_summaries_every_n_global_steps(args.i_img): - tf.contrib.summary.image( - 'rgb0', to8b(extras['rgb0'])[tf.newaxis]) - tf.contrib.summary.image( - 'disp0', extras['disp0'][tf.newaxis, ..., tf.newaxis]) - tf.contrib.summary.image( - 'z_std', extras['z_std'][tf.newaxis, ..., tf.newaxis]) + # with tf.summary.record_summaries_every_n_global_steps(args.i_img): + with writer.as_default(): + tf.summary.image( + 'rgb0', to8b(extras['rgb0'])[tf.newaxis], step=i) + tf.summary.image( + 'disp0', extras['disp0'][tf.newaxis, ..., tf.newaxis], step=i) + tf.summary.image( + 'z_std', extras['z_std'][tf.newaxis, ..., tf.newaxis], step=i) global_step.assign_add(1) diff --git a/run_nerf_helpers.py b/run_nerf_helpers.py index d84b0a49..4ca02f07 100644 --- a/run_nerf_helpers.py +++ b/run_nerf_helpers.py @@ -11,7 +11,7 @@ def img2mse(x, y): return tf.reduce_mean(tf.square(x - y)) -def mse2psnr(x): return -10.*tf.log(x)/tf.log(10.) +def mse2psnr(x): return -10.*tf.math.log(x)/tf.math.log(10.) def to8b(x): return (255*np.clip(x, 0, 1)).astype(np.uint8)