Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix imread call to use apply_gamma=False instead of ignoregamma=True #210

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM ubuntu:20.04

RUN apt-get install build-essential git python3-dev python3-pip libopenexr-dev libxi-dev \
libglfw3-dev libglew-dev libomp-dev libxinerama-dev libxcursor-dev
19 changes: 19 additions & 0 deletions MyLog/run1_observation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Run1 Observation

## Data
`image_4/` has higher resolution compared with `images_8/`
- `images` (Original data) has higher resolution compared with `images_4/`
- All folders contain images from 00-19. (Though their name is different)
Train data: [ 1 2 3 4 5 6 7 9 10 11 12 13 14 15 17 18 19]
Test and Val data: [0 8 16]

## Training - `train()` (from line 575)
- `nerf` model is created and define in `create_nerf(args)` function.

- main part are on the `Core optimization loop`.

## Nerf: `create_nerf(args)` (from line 378): initialize the NeRE's MLP model
- `init_nerf_model` (from `run_nerf_helpers.py`)



54 changes: 54 additions & 0 deletions dockerfiles_old/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Successfully built dockerfile to use Nsight Systems on Ubuntu 20.04 with pyenv and pyenv-virtualenv
FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu20.04

RUN apt-get update && \
apt-get install -y wget
# RUN git --version

# ## Install Nsight Systems
RUN wget https://developer.nvidia.com/downloads/assets/tools/secure/nsight-systems/2024_4/NsightSystems-linux-cli-public-2024.4.1.61-3431596.deb

# # Set the timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

RUN apt-get install -y ./NsightSystems-linux-cli-public-2024.4.1.61-3431596.deb

RUN rm ./NsightSystems-linux-cli-public-2024.4.1.61-3431596.deb && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN sysctl -w kernel.perf_event_paranoid=1

# ## Install basic tools (list of necessary tools are taken from https://qiita.com/nyakiri_0726/items/a33f404b5e1be9352b85)
# `apt-get update` is necessary before `apt-get install` to avoid error
# RUN apt-get update && apt-get install -y make build-essential git vim zlib1g-dev
RUN apt-get update && apt-get install -y build-essential git vim libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev \
liblzma-dev python-openssl git vim less

# # Environment variables
ENV HOME /root
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/bin:$PATH
ARG PYTHON_VERSION=3.7.17

RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv

RUN echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc && \
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc && \
echo 'eval "$(pyenv init -)"' >> ~/.bashrc && \
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc && \
echo 'export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python' >> ~/.bashrc

# it may takes time in `patching file setup.py`
RUN pyenv install 3.7.17

# Install pyenv-virtualenv
# NOTE: it should not be `$(PYENV_ROOT)/plugins/pyenv-virtualenv` but `$PYENV_ROOT/plugins/pyenv-virtualenv`
RUN git clone https://github.com/pyenv/pyenv-virtualenv.git $PYENV_ROOT/plugins/pyenv-virtualenv
RUN echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
# RUN source ~/.bashrc
RUN pyenv virtualenv 3.7.17 nerf_env


CMD [ "/bin/bash" ]
49 changes: 49 additions & 0 deletions dockerfiles_old/Dockerfile copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu20.04

RUN apt-get update && \
apt-get install -y wget

## Install Nsight Systems
RUN wget https://developer.nvidia.com/downloads/assets/tools/secure/nsight-systems/2024_4/NsightSystems-linux-cli-public-2024.4.1.61-3431596.deb

# Set the timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

RUN apt-get install -y ./NsightSystems-linux-cli-public-2024.4.1.61-3431596.deb

RUN rm ./NsightSystems-linux-cli-public-2024.4.1.61-3431596.deb && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN sysctl -w kernel.perf_event_paranoid=1

## Install basic tools
RUN apt-get install -y make build-essential
# RUN curl https://pyenv.run | bash
# RUN pyenv install 3.7.17

RUN echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc && \
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc && \
echo 'eval "$(pyenv init -)"' >> ~/.bashrc && \
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc && \
echo 'export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python' >> ~/.bashrc

# RUN /root/.pyenv/bin/pyenv install 3.7.17 && \
# /root/.pyenv/bin/pyenv global 3.7.17

RUN wget https://www.python.org/ftp/python/3.7.17/Python-3.7.17.tgz && \
tar -xzf Python-3.7.17.tgz

RUN cd Python-3.7.17 && \
./configure --enable-optimizations && \
make -j$(nproc) && \
make altinstall

RUN rm -rf Python-3.7.17 Python-3.7.17.tgz && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.7 1 && \
update-alternatives --install /usr/bin/pip3 pip3 /usr/local/bin/pip3.7 1

CMD [ "/bin/bash" ]
41 changes: 41 additions & 0 deletions dockerfiles_old/Dockerfile_torchprofiler
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM ubuntu:20.04

ENV HOME /root
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/bin:$PATH

# # Set the timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

RUN apt-get update && apt-get install -y wget build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev \
liblzma-dev python-openssl git vim less


RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv

RUN echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc && \
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc && \
echo 'eval "$(pyenv init -)"' >> ~/.bashrc && \
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc && \
echo 'export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python' >> ~/.bashrc

# it may takes time in `patching file setup.py`
RUN pyenv install 3.7.17

# Install pyenv-virtualenv
# NOTE: it should not be `$(PYENV_ROOT)/plugins/pyenv-virtualenv` but `$PYENV_ROOT/plugins/pyenv-virtualenv`
RUN git clone https://github.com/pyenv/pyenv-virtualenv.git $PYENV_ROOT/plugins/pyenv-virtualenv
RUN echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
# RUN source ~/.bashrc
RUN pyenv virtualenv 3.7.17 nerf_env

# RUN cd $PYENV_ROOT && \
# src/configure && \
# make -C src

RUN . $HOME/.bashrc
RUN pyenv activate nerf_env
RUN pip install -r requirements.txt
RUN pip install torchprofiler

2 changes: 1 addition & 1 deletion load_llff.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _load_data(basedir, factor=None, width=None, height=None, load_imgs=True):

def imread(f):
if f.endswith('png'):
return imageio.imread(f, ignoregamma=True)
return imageio.imread(f, apply_gamma=False)
else:
return imageio.imread(f)

Expand Down
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tensorflow-gpu==1.15
numpy
matplotlib
imageio
imageio-ffmpeg
configargparse
imagemagick
21 changes: 18 additions & 3 deletions run_nerf.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,7 @@ def train():
np.random.shuffle(rays_rgb)
print('done')
i_batch = 0

N_iters = 1000000
N_iters = 3
print('Begin')
print('TRAIN views are', i_train)
print('TEST views are', i_test)
Expand Down Expand Up @@ -802,16 +801,24 @@ def train():
batch_rays = tf.stack([rays_o, rays_d], 0)
target_s = tf.gather_nd(target, select_inds)

time1 = time.time()
ray_time = time1 - time0

##### Core optimization loop #####

with tf.GradientTape() as tape:

# Make predictions for color, disparity, accumulated opacity.
# NOTE: これがメインの処理: 3 -> 4に相当
time_before_render = time.time()
rgb, disp, acc, extras = render(
H, W, focal, chunk=args.chunk, rays=batch_rays,
verbose=i < 10, retraw=True, **render_kwargs_train)
time_after_render = time.time()
time_render = time_after_render - time_before_render

# Compute MSE loss between predicted and true RGB.
time_before_loss = time.time()
img_loss = img2mse(rgb, target_s)
trans = extras['raw'][..., -1]
loss = img_loss
Expand All @@ -822,9 +829,15 @@ def train():
img_loss0 = img2mse(extras['rgb0'], target_s)
loss += img_loss0
psnr0 = mse2psnr(img_loss0)

time_after_loss = time.time()
time_calc_loss = time_after_loss - time_before_loss

time2 = time.time()
gradients = tape.gradient(loss, grad_vars)
optimizer.apply_gradients(zip(gradients, grad_vars))
time3 = time.time()
time_backprop = time3 - time2

dt = time.time()-time0

Expand Down Expand Up @@ -874,7 +887,9 @@ def save_weights(net, prefix, i):
if i % args.i_print == 0 or i < 10:

print(expname, i, psnr.numpy(), loss.numpy(), global_step.numpy())
print('iter time {:.05f}'.format(dt))
print('iter time {:.05f} (ray calc: {:.05f} ({:.02f}%), rendering: {:.05f} ({:.02f}%), loss: {:.05f} ({:.02f}%), backprop: {:.05f} ({:.02f}%))'.format(dt, ray_time, ray_time/dt*100, time_render, time_render/dt*100, time_calc_loss, time_calc_loss/dt*100, time_backprop, time_backprop/dt*100))


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)
Expand Down
18 changes: 18 additions & 0 deletions sample.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "stdio.h"
__global__ void add(int a, int b, int *c)
{
*c = a + b;
}
int main()
{
int a, b, c;
int *dev_c;
a = 3;
b = 4;
cudaMalloc((void **)&dev_c, sizeof(int));
add<<<1, 1>>>(a, b, dev_c);
cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
printf("%d + %d is %d\n", a, b, c);
cudaFree(dev_c);
return 0;
}
29 changes: 29 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import torch
import torch.nn as nn

# Define a simple neural network
class SimpleNet(nn.Module):
def __init__(self):
super(SimpleNet, self).__init__()
self.conv1 = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, stride=1, padding=1)
self.fc1 = nn.Linear(32 * 8 * 8, 128)
self.fc2 = nn.Linear(128, 10)

def forward(self, x):
x = torch.relu(self.conv1(x))
x = torch.relu(self.conv2(x))
x = torch.flatten(x, 1)
x = torch.relu(self.fc1(x))
x = self.fc2(x)
return x

# Create a model instance
model = SimpleNet()

# Create a dummy input tensor
dummy_input = torch.randn(1, 3, 8, 8)

# Profile the FLOPS
output = model(dummy_input)
print("Finished!")
34 changes: 34 additions & 0 deletions test2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import torch
import torch.nn as nn
import torchprofile

# Define a simple neural network
class SimpleNet(nn.Module):
def __init__(self):
super(SimpleNet, self).__init__()
self.conv1 = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, stride=1, padding=1)
self.fc1 = nn.Linear(32 * 8 * 8, 128)
self.fc2 = nn.Linear(128, 10)

def forward(self, x):
x = torch.relu(self.conv1(x))
x = torch.relu(self.conv2(x))
x = torch.flatten(x, 1)
x = torch.relu(self.fc1(x))
x = self.fc2(x)
return x

# Create a model instance
model = SimpleNet()

# Create a dummy input tensor
dummy_input = torch.randn(1, 3, 8, 8)

# Profile the FLOPS
with torchprofile.profile(model, dummy_input) as profiler:
output = model(dummy_input)

# Print the profiling results
print(profiler)

33 changes: 33 additions & 0 deletions test3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import torch
import torch.nn as nn
from torchprofile import profile # Import the profile function

# Define a simple neural network
class SimpleNet(nn.Module):
def __init__(self):
super(SimpleNet, self).__init__()
self.conv1 = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, stride=1, padding=1)
self.fc1 = nn.Linear(32 * 8 * 8, 128)
self.fc2 = nn.Linear(128, 10)

def forward(self, x):
x = torch.relu(self.conv1(x))
x = torch.relu(self.conv2(x))
x = torch.flatten(x, 1)
x = torch.relu(self.fc1(x))
x = self.fc2(x)
return x

# Create a model instance
model = SimpleNet()

# Create a dummy input tensor
dummy_input = torch.randn(1, 3, 8, 8)

# Profile the FLOPS
with profile(model, dummy_input) as profiler:
output = model(dummy_input)

# Print the profiling results
print(profiler)
13 changes: 13 additions & 0 deletions test4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import tensorflow as tf

# Initialize profiler
tf.profiler.experimental.start(logdir='path/to/logs')

# Define and run your TensorFlow operations
a = tf.constant(1)
b = tf.constant(2)
c = a + b
print(c)

# Stop profiler
tf.profiler.experimental.stop()