Skip to content

Commit

Permalink
blearn: Add files
Browse files Browse the repository at this point in the history
  • Loading branch information
marcojob committed Oct 2, 2024
1 parent 965a1bb commit 98f3a9f
Show file tree
Hide file tree
Showing 26 changed files with 1,556 additions and 3 deletions.
52 changes: 52 additions & 0 deletions .devcontainer/blearn/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM nvcr.io/nvidia/pytorch:22.12-py3

ARG TZ=Europe/Zurich
ENV DEBIAN_FRONTEND=noninteractive
ENV BLENDER_DIR=/home/asl/blender
ARG VGLUSERS_GID=1004

# Base packages
COPY devcontainer_all_packages.sh /tmp/devcontainer_all_packages.sh
RUN /tmp/devcontainer_all_packages.sh && rm -f /tmp/devcontainer_all_packages.sh

ENV LANG="en_US.UTF-8" \
LANGUAGE="en_US:en" \
LC_ALL="en_US.UTF-8" \
BLENDER_USER_SCRIPTS=/home/asl/.config/blender/3.0/scripts/

# Add user "asl" with sudo rights
RUN groupadd -r asl && \
groupadd -g ${VGLUSERS_GID} vglusers && \
useradd --create-home --gid asl --groups dialout,plugdev,vglusers --shell /bin/bash asl && \
mkdir -p /etc/sudoers.d && \
echo 'asl ALL=NOPASSWD: ALL' > /etc/sudoers.d/asl

# Blender: Compile with patch that allows rendering depth in background
RUN apt-get --assume-yes install xpra subversion cmake libx11-dev libxxf86vm-dev libxcursor-dev libxi-dev libxrandr-dev libxinerama-dev libglew-dev
RUN mkdir -p $BLENDER_DIR/lib && cd $BLENDER_DIR/lib && svn checkout https://svn.blender.org/svnroot/bf-blender/tags/blender-3.0-release/lib/linux_centos7_x86_64/
RUN mkdir -p $BLENDER_DIR && cd $BLENDER_DIR && git clone https://github.com/marcojob/blender.git && cd blender && git checkout v3_0_1_background_patch && git submodule update --init --recursive
RUN cd $BLENDER_DIR/blender && make
RUN cd $BLENDER_DIR/blender && cmake ../build_linux -D WITH_CYCLES_CUDA_BINARIES=ON && make
RUN echo "alias blender='$BLENDER_DIR/build_linux/bin/blender'" >> /home/asl/.bash_aliases

# Blender: Install python deps
RUN $BLENDER_DIR/build_linux/bin/3.0/python/bin/python3.9 -m ensurepip
RUN $BLENDER_DIR/build_linux/bin/3.0/python/bin/python3.9 -m pip install pyyaml matplotlib scipy

# Blender: Copy user preferences to enable CUDA (ideally this would work with bpy, not figured out)
COPY userpref.blend /home/asl/.config/blender/3.0/config/

# Blender addon: Download and install BlenderGIS
RUN wget https://github.com/domlysz/BlenderGIS/archive/refs/tags/2210.zip -O /tmp/BlenderGIS-2210.zip && \
unzip /tmp/BlenderGIS-2210.zip -d /tmp/ && \
mkdir -p $BLENDER_USER_SCRIPTS/addons && \
mv /tmp/BlenderGIS-2210 $BLENDER_USER_SCRIPTS/addons/BlenderGIS && \
$BLENDER_DIR/build_linux/bin/blender -b --python-expr "import bpy; bpy.ops.preferences.addon_enable(module='BlenderGIS'); bpy.ops.wm.save_userpref()"

# Git-prompt: Source
RUN echo 'if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then GIT_PROMPT_ONLY_IN_REPO=1; source "$HOME/.bash-git-prompt/gitprompt.sh"; fi' >> /home/asl/.bash_aliases

# Clean up
RUN rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* /var/cache/apt/archives/*

ENTRYPOINT ["/bin/bash"]
54 changes: 54 additions & 0 deletions .devcontainer/blearn/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"image": "omavteam/radarmeetsvision:blearn-latest",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python"
],
"settings": {
"files.hotExit": "off",
"window.restoreWindows": "none",
"workbench.startupEditor": "none"
}
}
},
"remoteEnv": {
"DISPLAY": "${localEnv:DISPLAY}"
},
"remoteUser": "asl",
"initializeCommand": ".devcontainer/devcontainer_optional_mounts.sh",
"postStartCommand": "pip install -e .",
"mounts": [
{
"source": "${localEnv:HOME}/.bash-git-prompt",
"target": "/home/asl/.bash-git-prompt",
"type": "bind"
},
{
"source": "${localEnv:HOME}/Downloads",
"target": "/home/asl/Downloads",
"type": "bind"
},
{
"source": "${localEnv:HOME}/Storage",
"target": "/home/asl/Storage",
"type": "bind"
},
{
"source": "${localEnv:HOME}/.cache",
"target": "/home/asl/.cache",
"type": "bind"
}
],
"runArgs": [
"--gpus",
"all",
"--privileged",
"--device=/dev/dri:/dev/dri",
"-v",
"/tmp/.X11-unix:/tmp/.X11-unix",
"-v",
"/dev/bus/usb:/dev/bus/usb",
"--net=host"
]
}
1 change: 1 addition & 0 deletions .devcontainer/build_and_push_images.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
docker buildx build -t omavteam/radarmeetsvision:blearn-latest -f blearn/Dockerfile --push .
docker buildx build -t omavteam/radarmeetsvision:latest -f desktop/Dockerfile --push .
4 changes: 2 additions & 2 deletions .devcontainer/desktop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/hpcx/ompi/lib"
ENV PATH="${PATH}:/opt/hpcx/ompi/bin"

# All apt packages
COPY devcontainer-all-packages.sh /tmp/devcontainer-all-packages.sh
RUN /tmp/devcontainer-all-packages.sh && rm -f /tmp/devcontainer-all-packages.sh
COPY devcontainer_all_packages.sh /tmp/devcontainer_all_packages.sh
RUN /tmp/devcontainer_all_packages.sh && rm -f /tmp/devcontainer_all_packages.sh

ENV LANG="en_US.UTF-8" \
LANGUAGE="en_US:en" \
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/desktop/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"DISPLAY": "${localEnv:DISPLAY}"
},
"remoteUser": "asl",
"initializeCommand": ".devcontainer/devcontainer-optional-mounts.sh",
"initializeCommand": ".devcontainer/devcontainer_optional_mounts.sh",
"postStartCommand": "pip install -e .",
"mounts": [
{
Expand Down
File renamed without changes.
Binary file added .devcontainer/userpref.blend
Binary file not shown.
26 changes: 26 additions & 0 deletions blearn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<p align="center">
<img src="docs/banner.png?raw=true" width="750" height="375">
</p>
**blearn** is a tool that allows you to generate an image-based dataset in Blender. Together with a mesh and texture obtained from photogrammetry, realistic synthetic datasets can be generated. The script is executed with Blender built-in python interpreter, which has the advantage that `bpy` is already loaded correctly

### Requirements
Install all requirements with:
```bash
pip3 install -r requirements.txt
```

### Example
```bash
blender -b <path_to_blend_file>.blend --python blearn.py
```

### Running tests
```bash
python -m pytest
```

### Offload to GPU with Nvidia prime on-demand
When using Nvidia prime with the on-demand setting, the use of the GPU must be force using the following env definitions:
```bash
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia blender <path_to_blend_file>.blend --python blearn.py
```
28 changes: 28 additions & 0 deletions blearn/blearn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3

""" Main script to run blearn, generating a learning dataset in Blender"""


__author__ = "Marco Job"

import sys
import os
import bpy

# Setup the path to find modules
dn = os.path.dirname(__file__)

if dn not in sys.path:
sys.path.append(dn)

# Import own code now
from src.blender import Blender # NOQA


def main():
b = Blender(config_file="config/config_road_corridor_demo.yml")
b.start()


if __name__ == "__main__":
main()
51 changes: 51 additions & 0 deletions blearn/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
camera:
f: 3.5
sx: 4.96
sy: 3.72
sun:
energy_min: 10.0
energy_max: 10.0
local_time_min: 10.0
local_time_max: 16.0
output:
dir: output
resolution_x: 640
resolution_y: 480
format: JPEG
render: CYCLES
use_second_view: True
paths:
number_of_samples: 10000
x_min: 0.0
x_max: 600.0
y_min: 0.0
y_max: 250.0
z_min: 1.0
z_max: 51.0
euler_x_min: -0.1745
euler_x_max: 0.1745
euler_y_min: -0.1745
euler_y_max: 0.1745
euler_z_min: -3.141
euler_z_max: 3.141
seed: 1
demo:
radius: 20.0
x: 200.0
y: 100.0
z: 30.0
landing:
x: 351.1
y: 102.9
z_start: 51.0
z_end: 0.0
down_vel: 0.5
side_acc: 1.0
fps: 20
euler_x_min: -0.1745
euler_x_max: 0.1745
euler_y_min: -0.1745
euler_y_max: 0.1745
euler_z_min: -0.087
euler_z_max: 0.087
poses_file: /media/scratch2/mjob/poses.txt
36 changes: 36 additions & 0 deletions blearn/config/config_aeschhandheld2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
mode: "validation"
camera:
f: 4.143903289
sx: 4.968
sy: 3.726
sun:
energy_min: 10.0
energy_max: 10.0
local_time_min: 10.0
local_time_max: 16.0
output:
dir: output
resolution_x: 1280
resolution_y: 960
format: JPEG
render: CYCLES
use_second_view: False
paths:
number_of_samples: 10000
x_min: 0.0
x_max: 1400.0
y_min: 0.0
y_max: 1000.0
z_min: 1.0
z_max: 51.0
euler_x_min: -0.1745
euler_x_max: 0.1745
euler_y_min: -0.1745
euler_y_max: 0.1745
euler_z_min: -3.141
euler_z_max: 3.141
seed: 1
pix4d_trajectory: '/home/don/Storage/02_Pix4D_datasets/AeschHandheld2/aesch_handheld2_exif/aesch_handheld2_exif/1_initial/params/aesch_handheld2_exif_calibrated_external_camera_parameters.txt'
offset_x: 456612.000
offset_y: 5243305.000
offset_z: 557.000
36 changes: 36 additions & 0 deletions blearn/config/config_maschinenhalle0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
mode: "validation"
camera:
f: 4.143903289
sx: 4.968
sy: 3.726
sun:
energy_min: 10.0
energy_max: 10.0
local_time_min: 10.0
local_time_max: 16.0
output:
dir: output
resolution_x: 1280
resolution_y: 960
format: JPEG
render: CYCLES
use_second_view: False
paths:
number_of_samples: 10000
x_min: 0.0
x_max: 1400.0
y_min: 0.0
y_max: 1000.0
z_min: 1.0
z_max: 51.0
euler_x_min: -0.1745
euler_x_max: 0.1745
euler_y_min: -0.1745
euler_y_max: 0.1745
euler_z_min: -3.141
euler_z_max: 3.141
seed: 1
pix4d_trajectory: '/home/don/Storage/05_Blender_Projects/Maschinenhalle/maschinenhalle0_minimal_calibrated_external_camera_parameters.txt'
offset_x: 465843.000
offset_y: 5247237.000
offset_z: 456.000
31 changes: 31 additions & 0 deletions blearn/config/config_mountain_area.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
mode: "training"
camera:
f: 4.143903289
sx: 4.968
sy: 3.726
sun:
energy_min: 10.0
energy_max: 10.0
local_time_min: 10.0
local_time_max: 16.0
output:
dir: output
resolution_x: 640
resolution_y: 480
format: JPEG
render: CYCLES
paths:
number_of_samples: 10000
x_min: 0.0
x_max: 1400.0
y_min: 0.0
y_max: 1000.0
z_min: 1.0
z_max: 51.0
euler_x_min: -0.3926991
euler_x_max: 0.3926991
euler_y_min: -0.3926991
euler_y_max: 0.3926991
euler_z_min: -3.141
euler_z_max: 3.141
seed: 1
35 changes: 35 additions & 0 deletions blearn/config/config_mountain_area_demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
mode: "demo"
camera:
f: 4.143903289
sx: 4.968
sy: 3.726
sun:
energy_min: 10.0
energy_max: 10.0
local_time_min: 10.0
local_time_max: 16.0
output:
dir: output
resolution_x: 640
resolution_y: 480
format: JPEG
render: CYCLES
paths:
number_of_samples: 100
x_min: 0.0
x_max: 1400.0
y_min: 0.0
y_max: 1000.0
z_min: 1.0
z_max: 51.0
euler_x_min: -0.3926991
euler_x_max: 0.3926991
euler_y_min: -0.3926991
euler_y_max: 0.3926991
euler_z_min: -3.141
euler_z_max: 3.141
seed: 1
demo_x: 700.0
demo_y: 450.0
demo_z: 50.0
demo_radius: 50.0
Loading

0 comments on commit 98f3a9f

Please sign in to comment.