Spaces:
Sleeping
Sleeping
initial commit
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +44 -0
- Dockerfile +80 -0
- dermsynth3d.yml +204 -0
- gradio_app.py +1014 -0
- hf_demo/lesions/006-f-run/lesion_dilated_mask_demo.png +0 -0
- hf_demo/lesions/006-f-run/lesion_dilated_mask_latest.png +0 -0
- hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_1.png +0 -0
- hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_10.png +0 -0
- hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_15.png +0 -0
- hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_2.png +0 -0
- hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_30.png +0 -0
- hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_5.png +0 -0
- hf_demo/lesions/006-f-run/lesion_mask_latest.png +0 -0
- hf_demo/lesions/006-f-run/lesion_mask_lesion_0.png +0 -0
- hf_demo/lesions/006-f-run/lesion_mask_lesion_1.png +0 -0
- hf_demo/lesions/006-f-run/lesion_mask_lesion_10.png +0 -0
- hf_demo/lesions/006-f-run/lesion_mask_lesion_15.png +0 -0
- hf_demo/lesions/006-f-run/lesion_mask_lesion_2.png +0 -0
- hf_demo/lesions/006-f-run/lesion_mask_lesion_30.png +0 -0
- hf_demo/lesions/006-f-run/lesion_mask_lesion_5.png +0 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_demo.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_latest.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_1.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_10.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_15.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_2.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_30.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_5.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_demo.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_latest.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_1.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_10.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_15.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_2.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_30.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_5.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_lesion_0.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_mask.png +0 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_demo.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_latest.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_1.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_10.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_15.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_2.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_30.png +3 -0
- hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_5.png +3 -0
- hf_demo/lesions/221-m-u/lesion_dilated_mask_lesion_1.png +0 -0
- hf_demo/lesions/221-m-u/lesion_dilated_mask_lesion_10.png +0 -0
- hf_demo/lesions/221-m-u/lesion_dilated_mask_lesion_15.png +0 -0
- hf_demo/lesions/221-m-u/lesion_dilated_mask_lesion_2.png +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,47 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_demo.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_latest.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_1.png filter=lfs diff=lfs merge=lfs -text
|
39 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_10.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_15.png filter=lfs diff=lfs merge=lfs -text
|
41 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_2.png filter=lfs diff=lfs merge=lfs -text
|
42 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_30.png filter=lfs diff=lfs merge=lfs -text
|
43 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_5.png filter=lfs diff=lfs merge=lfs -text
|
44 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_demo.png filter=lfs diff=lfs merge=lfs -text
|
45 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_latest.png filter=lfs diff=lfs merge=lfs -text
|
46 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_1.png filter=lfs diff=lfs merge=lfs -text
|
47 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_10.png filter=lfs diff=lfs merge=lfs -text
|
48 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_15.png filter=lfs diff=lfs merge=lfs -text
|
49 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_2.png filter=lfs diff=lfs merge=lfs -text
|
50 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_30.png filter=lfs diff=lfs merge=lfs -text
|
51 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_5.png filter=lfs diff=lfs merge=lfs -text
|
52 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_lesion_0.png filter=lfs diff=lfs merge=lfs -text
|
53 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_demo.png filter=lfs diff=lfs merge=lfs -text
|
54 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_latest.png filter=lfs diff=lfs merge=lfs -text
|
55 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_1.png filter=lfs diff=lfs merge=lfs -text
|
56 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_10.png filter=lfs diff=lfs merge=lfs -text
|
57 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_15.png filter=lfs diff=lfs merge=lfs -text
|
58 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_2.png filter=lfs diff=lfs merge=lfs -text
|
59 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_30.png filter=lfs diff=lfs merge=lfs -text
|
60 |
+
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_5.png filter=lfs diff=lfs merge=lfs -text
|
61 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_blended_lesion_1.png filter=lfs diff=lfs merge=lfs -text
|
62 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_blended_lesion_10.png filter=lfs diff=lfs merge=lfs -text
|
63 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_blended_lesion_15.png filter=lfs diff=lfs merge=lfs -text
|
64 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_blended_lesion_2.png filter=lfs diff=lfs merge=lfs -text
|
65 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_blended_lesion_30.png filter=lfs diff=lfs merge=lfs -text
|
66 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_blended_lesion_5.png filter=lfs diff=lfs merge=lfs -text
|
67 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_dilated_lesion_1.png filter=lfs diff=lfs merge=lfs -text
|
68 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_dilated_lesion_10.png filter=lfs diff=lfs merge=lfs -text
|
69 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_dilated_lesion_15.png filter=lfs diff=lfs merge=lfs -text
|
70 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_dilated_lesion_2.png filter=lfs diff=lfs merge=lfs -text
|
71 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_dilated_lesion_30.png filter=lfs diff=lfs merge=lfs -text
|
72 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_dilated_lesion_5.png filter=lfs diff=lfs merge=lfs -text
|
73 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_lesion_0.png filter=lfs diff=lfs merge=lfs -text
|
74 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_pasted_lesion_1.png filter=lfs diff=lfs merge=lfs -text
|
75 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_pasted_lesion_10.png filter=lfs diff=lfs merge=lfs -text
|
76 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_pasted_lesion_15.png filter=lfs diff=lfs merge=lfs -text
|
77 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_pasted_lesion_2.png filter=lfs diff=lfs merge=lfs -text
|
78 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_pasted_lesion_30.png filter=lfs diff=lfs merge=lfs -text
|
79 |
+
hf_demo/lesions/221-m-u/model_highres_0_normalized_pasted_lesion_5.png filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM nvidia/cuda:11.3.1-cudnn8-runtime-ubuntu20.04
|
2 |
+
|
3 |
+
# FROM pytorch/pytorch:1.12.1-cuda11.3-cudnn8-devel
|
4 |
+
|
5 |
+
|
6 |
+
RUN echo $CUDA_HOME
|
7 |
+
# ENV LD_LIBRARY_PATH /usr/local/cuda/lib64/stubs/:$LD_LIBRARY_PATH
|
8 |
+
# ENV CUDA_HOME /usr/local/cuda
|
9 |
+
# ENV LD_LIBRARY_PATH /usr/local/cuda/lib64/:$LD_LIBRARY_PATH
|
10 |
+
# ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
11 |
+
# ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
|
12 |
+
# ENV PATH=/opt/conda/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
13 |
+
# ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
|
14 |
+
#
|
15 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
16 |
+
ARG UID=1000
|
17 |
+
ARG GID=1000
|
18 |
+
ARG USER=developer
|
19 |
+
ARG GROUP=$USER
|
20 |
+
|
21 |
+
ENV FORCE_CUDA=1
|
22 |
+
RUN echo $(nvcc --version)
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
# Install necessary packages
|
27 |
+
RUN --mount=type=cache,target=/var/cache/apt apt update && apt install -y --no-install-recommends \
|
28 |
+
sudo \
|
29 |
+
git \
|
30 |
+
wget \
|
31 |
+
bzip2 \
|
32 |
+
ca-certificates \
|
33 |
+
libx11-6 \
|
34 |
+
python3-opencv \
|
35 |
+
vim \
|
36 |
+
&& rm -rf /var/lib/apt/lists/*
|
37 |
+
|
38 |
+
## Create a non-root user and group
|
39 |
+
RUN addgroup --gid $GID $GROUP
|
40 |
+
RUN adduser --disabled-password --gecos '' --uid $UID --gid $GID $USER && \
|
41 |
+
adduser $USER sudo && \
|
42 |
+
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
43 |
+
# RUN useradd -D -mU ${USER} --uid=${UID}
|
44 |
+
# Run as this user from now on
|
45 |
+
USER $USER:$GID
|
46 |
+
|
47 |
+
# Install Miniconda
|
48 |
+
WORKDIR /home/$USER
|
49 |
+
RUN wget -q https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh \
|
50 |
+
&& /bin/bash ~/miniconda.sh -b -p ~/miniconda \
|
51 |
+
&& rm ~/miniconda.sh
|
52 |
+
ENV PATH=/home/$USER/miniconda/bin:$PATH
|
53 |
+
|
54 |
+
RUN git clone --recurse-submodules https://github.com/sfu-mial/DermSynth3D.git
|
55 |
+
WORKDIR /home/$USER/DermSynth3D
|
56 |
+
|
57 |
+
# Set up conda environment
|
58 |
+
COPY . .
|
59 |
+
COPY dermsynth3d.yml .
|
60 |
+
RUN conda env create -f dermsynth3d.yml && conda clean -afy
|
61 |
+
ENV CONDA_DEFAULT_ENV=dermsynth3d
|
62 |
+
ENV CONDA_PREFIX=/home/$USER/miniconda/envs/$CONDA_DEFAULT_ENV
|
63 |
+
ENV PATH=$CONDA_PREFIX/bin:$PATH
|
64 |
+
|
65 |
+
|
66 |
+
RUN echo "source activate $(head -1 dermsynth3d.yml | cut -d' ' -f2)" > ~/.bashrc
|
67 |
+
ENV PATH /home/$USER/miniconda/envs/$(head -1 dermsynth3d.yml | cut -d' ' -f2)/bin:$PATH
|
68 |
+
|
69 |
+
# Copy code
|
70 |
+
# COPY data /demo_data
|
71 |
+
# COPY . /home/$USER/DermSynth3D
|
72 |
+
|
73 |
+
COPY . .
|
74 |
+
# Test imports
|
75 |
+
# RUN git clone --recurse-submodules https://github.com/sfu-mial/DermSynth3D.git
|
76 |
+
#, "python", "scripts/gen_data.py"]
|
77 |
+
WORKDIR /home/$USER/DermSynth3D
|
78 |
+
RUN pip install gradio fire streamlit
|
79 |
+
# CMD ["streamlit", "run", "app.py"]
|
80 |
+
CMD ["gradio", "gradio_app.py"]
|
dermsynth3d.yml
ADDED
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: dermsynth3d
|
2 |
+
channels:
|
3 |
+
- pytorch3d
|
4 |
+
- iopath
|
5 |
+
- bottler
|
6 |
+
- pytorch
|
7 |
+
- fvcore
|
8 |
+
- pytorch
|
9 |
+
- conda-forge
|
10 |
+
- defaults
|
11 |
+
dependencies:
|
12 |
+
- _libgcc_mutex=0.1=conda_forge
|
13 |
+
- _openmp_mutex=4.5=2_kmp_llvm
|
14 |
+
- brotlipy=0.7.0=py38h27cfd23_1003
|
15 |
+
- ca-certificates=2022.12.7=ha878542_0
|
16 |
+
- certifi=2022.12.7=py38h06a4308_0
|
17 |
+
- cffi=1.15.1=py38h4a40e3a_3
|
18 |
+
- charset-normalizer=2.0.4=pyhd3eb1b0_0
|
19 |
+
- colorama=0.4.6=pyhd8ed1ab_0
|
20 |
+
- cryptography=38.0.1=py38h9ce1e76_0
|
21 |
+
- cudatoolkit=11.3.1=h2bc3f7f_2
|
22 |
+
- freetype=2.12.1=hca18f0e_1
|
23 |
+
- future=0.18.2=pyhd8ed1ab_6
|
24 |
+
- fvcore=0.1.5.post20210915=py38
|
25 |
+
- idna=3.4=py38h06a4308_0
|
26 |
+
- intel-openmp=2021.4.0=h06a4308_3561
|
27 |
+
- iopath=0.1.9=py38
|
28 |
+
- jbig=2.1=h7f98852_2003
|
29 |
+
- jpeg=9e=h166bdaf_2
|
30 |
+
- lcms2=2.12=hddcbb42_0
|
31 |
+
- ld_impl_linux-64=2.38=h1181459_1
|
32 |
+
- lerc=3.0=h295c915_0
|
33 |
+
- libblas=3.9.0=12_linux64_mkl
|
34 |
+
- libcblas=3.9.0=12_linux64_mkl
|
35 |
+
- libdeflate=1.8=h7f8727e_5
|
36 |
+
- libffi=3.4.2=h6a678d5_6
|
37 |
+
- libgcc-ng=12.2.0=h65d4601_19
|
38 |
+
- liblapack=3.9.0=12_linux64_mkl
|
39 |
+
- libpng=1.6.39=h753d276_0
|
40 |
+
- libprotobuf=3.19.4=h780b84a_0
|
41 |
+
- libstdcxx-ng=11.2.0=h1234567_1
|
42 |
+
- libtiff=4.3.0=h6f004c6_2
|
43 |
+
- libwebp-base=1.2.4=h166bdaf_0
|
44 |
+
- libzlib=1.2.13=h166bdaf_4
|
45 |
+
- llvm-openmp=15.0.6=he0ac6c6_0
|
46 |
+
- lz4-c=1.9.3=h9c3ff4c_1
|
47 |
+
- mkl=2021.4.0=h06a4308_640
|
48 |
+
- ncurses=6.3=h5eee18b_3
|
49 |
+
- ninja=1.11.0=h924138e_0
|
50 |
+
- numpy=1.22.3=py38h99721a1_2
|
51 |
+
- olefile=0.46=pyh9f0ad1d_1
|
52 |
+
- openjpeg=2.5.0=h7d73246_0
|
53 |
+
- openssl=1.1.1s=h0b41bf4_1
|
54 |
+
- pillow=8.4.0=py38h8e6f84c_0
|
55 |
+
- pip=22.3.1=py38h06a4308_0
|
56 |
+
- portalocker=2.6.0=py38h578d9bd_1
|
57 |
+
- pycparser=2.21=pyhd8ed1ab_0
|
58 |
+
- pyopenssl=22.0.0=pyhd3eb1b0_0
|
59 |
+
- pysocks=1.7.1=py38h06a4308_0
|
60 |
+
- python=3.8.15=h7a1cb2a_2
|
61 |
+
- python_abi=3.8=2_cp38
|
62 |
+
- pytorch
|
63 |
+
- torchvision
|
64 |
+
- pytorch3d=0.7.2=py38_cu113_pyt1100
|
65 |
+
- pyyaml=6.0=py38h0a891b7_5
|
66 |
+
- readline=8.2=h5eee18b_0
|
67 |
+
- requests=2.28.1=py38h06a4308_0
|
68 |
+
- setuptools=65.5.0=py38h06a4308_0
|
69 |
+
- six=1.16.0=pyh6c4a22f_0
|
70 |
+
- sleef=3.5.1=h9b69904_2
|
71 |
+
- sqlite=3.40.0=h5082296_0
|
72 |
+
- tabulate=0.9.0=pyhd8ed1ab_1
|
73 |
+
- termcolor=2.1.1=pyhd8ed1ab_0
|
74 |
+
- tk=8.6.12=h1ccaba5_0
|
75 |
+
- tqdm=4.64.1=pyhd8ed1ab_0
|
76 |
+
- typing_extensions=4.4.0=pyha770c72_0
|
77 |
+
- urllib3=1.26.13=py38h06a4308_0
|
78 |
+
- wheel=0.37.1=pyhd3eb1b0_0
|
79 |
+
- xz=5.2.8=h5eee18b_0
|
80 |
+
- yacs=0.1.8=pyhd8ed1ab_0
|
81 |
+
- yaml=0.2.5=h7f98852_2
|
82 |
+
- zlib=1.2.13=h166bdaf_4
|
83 |
+
- zstd=1.5.2=h8a70e8d_1
|
84 |
+
- pip:
|
85 |
+
- absl-py==1.4.0
|
86 |
+
- albumentations==1.3.0
|
87 |
+
- anyio==3.6.2
|
88 |
+
- argon2-cffi==21.3.0
|
89 |
+
- argon2-cffi-bindings==21.2.0
|
90 |
+
- arrow==1.2.3
|
91 |
+
- asttokens==2.2.1
|
92 |
+
- attrs==22.2.0
|
93 |
+
- babel==2.11.0
|
94 |
+
- backcall==0.2.0
|
95 |
+
- beautifulsoup4==4.11.1
|
96 |
+
- bleach==5.0.1
|
97 |
+
- boto3==1.26.47
|
98 |
+
- botocore==1.29.47
|
99 |
+
- comm==0.1.2
|
100 |
+
- contourpy==1.0.6
|
101 |
+
- cycler==0.11.0
|
102 |
+
- debugpy==1.6.4
|
103 |
+
- decorator==5.1.1
|
104 |
+
- defusedxml==0.7.1
|
105 |
+
- entrypoints==0.4
|
106 |
+
- executing==1.2.0
|
107 |
+
- fastjsonschema==2.16.2
|
108 |
+
- fonttools==4.38.0
|
109 |
+
- fqdn==1.5.1
|
110 |
+
- imageio==2.23.0
|
111 |
+
- importlib-metadata==5.2.0
|
112 |
+
- importlib-resources==5.10.2
|
113 |
+
- ipykernel==6.19.4
|
114 |
+
- ipython==8.7.0
|
115 |
+
- ipython-genutils==0.2.0
|
116 |
+
- ipywidgets==8.0.4
|
117 |
+
- isoduration==20.11.0
|
118 |
+
- jedi==0.18.2
|
119 |
+
- jinja2==3.1.2
|
120 |
+
- jmespath==1.0.1
|
121 |
+
- joblib==1.2.0
|
122 |
+
- json5==0.9.10
|
123 |
+
- jsonpointer==2.3
|
124 |
+
- jsonschema==4.17.3
|
125 |
+
- jupyter-client==7.4.8
|
126 |
+
- jupyter-core==5.1.1
|
127 |
+
- jupyter-events==0.5.0
|
128 |
+
- jupyter-server==2.0.6
|
129 |
+
- jupyter-server-terminals==0.4.3
|
130 |
+
- jupyterlab==3.5.2
|
131 |
+
- jupyterlab-pygments==0.2.2
|
132 |
+
- jupyterlab-server==2.17.0
|
133 |
+
- jupyterlab-widgets==3.0.5
|
134 |
+
- kiwisolver==1.4.4
|
135 |
+
- markupsafe==2.1.1
|
136 |
+
- matplotlib==3.6.2
|
137 |
+
- matplotlib-inline==0.1.6
|
138 |
+
- mistune==2.0.4
|
139 |
+
- nbclassic==0.4.8
|
140 |
+
- nbclient==0.7.2
|
141 |
+
- nbconvert==7.2.7
|
142 |
+
- nbformat==5.7.1
|
143 |
+
- nest-asyncio==1.5.6
|
144 |
+
- networkx==2.8.8
|
145 |
+
- nibabel==5.0.0
|
146 |
+
- notebook==6.5.2
|
147 |
+
- mediapy
|
148 |
+
- fire
|
149 |
+
- streamlit
|
150 |
+
- gradio
|
151 |
+
- notebook-shim==0.2.2
|
152 |
+
- opencv-python==4.6.0.66
|
153 |
+
- opencv-python-headless==4.6.0.66
|
154 |
+
- packaging==22.0
|
155 |
+
- pandas==1.5.2
|
156 |
+
- pandocfilters==1.5.0
|
157 |
+
- parso==0.8.3
|
158 |
+
- pexpect==4.8.0
|
159 |
+
- pickleshare==0.7.5
|
160 |
+
- pkgutil-resolve-name==1.3.10
|
161 |
+
- platformdirs==2.6.2
|
162 |
+
- prometheus-client==0.15.0
|
163 |
+
- prompt-toolkit==3.0.36
|
164 |
+
- psutil==5.9.4
|
165 |
+
- ptyprocess==0.7.0
|
166 |
+
- pure-eval==0.2.2
|
167 |
+
- pygments==2.13.0
|
168 |
+
- pyparsing==3.0.9
|
169 |
+
- pyrsistent==0.19.3
|
170 |
+
- python-dateutil==2.8.2
|
171 |
+
- python-json-logger==2.0.4
|
172 |
+
- pytz==2022.7
|
173 |
+
- pywavelets==1.4.1
|
174 |
+
- pyzmq==24.0.1
|
175 |
+
- qudida==0.0.4
|
176 |
+
- regex==2022.10.31
|
177 |
+
- rfc3339-validator==0.1.4
|
178 |
+
- rfc3986-validator==0.1.1
|
179 |
+
- rtree==1.0.1
|
180 |
+
- s3transfer==0.6.0
|
181 |
+
- scikit-image==0.19.3
|
182 |
+
- scikit-learn==1.2.0
|
183 |
+
- scipy==1.9.3
|
184 |
+
- seaborn==0.12.2
|
185 |
+
- send2trash==1.8.0
|
186 |
+
- sniffio==1.3.0
|
187 |
+
- soupsieve==2.3.2.post1
|
188 |
+
- stack-data==0.6.2
|
189 |
+
- terminado==0.17.1
|
190 |
+
- threadpoolctl==3.1.0
|
191 |
+
- tornado==6.2
|
192 |
+
- traitlets==5.8.0
|
193 |
+
- trimesh==3.17.1
|
194 |
+
- uri-template==1.2.0
|
195 |
+
- wcwidth==0.2.5
|
196 |
+
- webcolors==1.12
|
197 |
+
- webencodings==0.5.1
|
198 |
+
- websocket-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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from functools import partial
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
import gradio as gr
|
7 |
+
import torch
|
8 |
+
import os
|
9 |
+
import fire
|
10 |
+
import multiprocessing as mp
|
11 |
+
import os, sys
|
12 |
+
|
13 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), "DermSynth3D"))
|
14 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), "DermSynth3D", "dermsynth3d"))
|
15 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), "DermSynth3D", "skin3d"))
|
16 |
+
|
17 |
+
import pandas as pd
|
18 |
+
import numpy as np
|
19 |
+
from glob import glob
|
20 |
+
from PIL import Image
|
21 |
+
import torch
|
22 |
+
import torch.nn as nn
|
23 |
+
import trimesh
|
24 |
+
import plotly.graph_objects as go
|
25 |
+
from plotly.subplots import make_subplots
|
26 |
+
|
27 |
+
import math
|
28 |
+
from trimesh import transformations as tf
|
29 |
+
import os
|
30 |
+
from math import pi
|
31 |
+
import matplotlib.pyplot as plt
|
32 |
+
import plotly
|
33 |
+
|
34 |
+
import plotly.graph_objects as go
|
35 |
+
from skimage import io
|
36 |
+
|
37 |
+
view_width = 400
|
38 |
+
view_height = 400
|
39 |
+
|
40 |
+
import mediapy as mpy
|
41 |
+
|
42 |
+
try:
|
43 |
+
from pytorch3d.io import load_objs_as_meshes
|
44 |
+
from pytorch3d.structures import Meshes
|
45 |
+
|
46 |
+
from pytorch3d.renderer import (
|
47 |
+
look_at_view_transform,
|
48 |
+
FoVPerspectiveCameras,
|
49 |
+
PointLights,
|
50 |
+
DirectionalLights,
|
51 |
+
Materials,
|
52 |
+
RasterizationSettings,
|
53 |
+
MeshRenderer,
|
54 |
+
MeshRasterizer,
|
55 |
+
SoftPhongShader,
|
56 |
+
TexturesUV,
|
57 |
+
TexturesVertex,
|
58 |
+
)
|
59 |
+
|
60 |
+
print("Pytorch3d compiled properly")
|
61 |
+
except:
|
62 |
+
print("Pytorch3d not compiled properly. Install pytorch3d with torch/cuda support")
|
63 |
+
|
64 |
+
try:
|
65 |
+
sys.path.append("./DermSynth3D/")
|
66 |
+
sys.path.append("./DermSynth3D/dermsynth3d/")
|
67 |
+
sys.path.append("./DermSynth3D/skin3d/")
|
68 |
+
from dermsynth3d import BlendLesions, Generate2DViews, SelectAndPaste
|
69 |
+
from dermsynth3d.tools.generate2d import Generate2DHelper
|
70 |
+
from dermsynth3d.utils.utils import yaml_loader
|
71 |
+
from dermsynth3d.utils.utils import random_bound, make_masks
|
72 |
+
from dermsynth3d.tools.synthesize import Synthesize2D
|
73 |
+
from dermsynth3d.datasets.synth_dataset import SynthesizeDataset
|
74 |
+
from dermsynth3d.tools.renderer import (
|
75 |
+
MeshRendererPyTorch3D,
|
76 |
+
camera_pos_from_normal,
|
77 |
+
)
|
78 |
+
from dermsynth3d.deepblend.blend3d import Blended3d
|
79 |
+
from dermsynth3d.utils.channels import Target
|
80 |
+
from dermsynth3d.utils.tensor import (
|
81 |
+
pil_to_tensor,
|
82 |
+
)
|
83 |
+
from dermsynth3d.utils.colorconstancy import shade_of_gray_cc
|
84 |
+
from dermsynth3d.datasets.datasets import Fitz17KAnnotations, Background2d
|
85 |
+
from skin3d.skin3d.bodytex import BodyTexDataset
|
86 |
+
|
87 |
+
print("DermSynth3D compiled properly")
|
88 |
+
except Exception as e:
|
89 |
+
print(e)
|
90 |
+
print("DermSynth3D not in the path. Make sure to add it to the path.")
|
91 |
+
|
92 |
+
_TITLE = """DermSynth3D: A Framework for generating Synthetic Dermatological Images"""
|
93 |
+
_DESCRIPTION = """
|
94 |
+
**Step 1**. Select the Mesh, texture map and number of lesions from the dropdown or select an example.</br>
|
95 |
+
**Step 2**. Selct the number of views to render. </br>
|
96 |
+
**Step 3** (optional). Randomize the view parameters by clicking on the checkbox.</br>
|
97 |
+
**Step 4**. Click on the Render Views button to render the views. </br>
|
98 |
+
"""
|
99 |
+
|
100 |
+
|
101 |
+
deployed = True
|
102 |
+
|
103 |
+
if deployed:
|
104 |
+
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
105 |
+
global DEVICE
|
106 |
+
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
107 |
+
if torch.cuda.is_available():
|
108 |
+
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
109 |
+
else:
|
110 |
+
print("Running on CPU")
|
111 |
+
|
112 |
+
global mesh_paths, mesh_names, all_textures, dir_blended_textures, dir_anatomy
|
113 |
+
global get_no_lesion_path, get_mesh_path, get_mask_path, get_dilated_lesion_path
|
114 |
+
global get_blended_lesion_path, get_pasted_lesion_path, get_texture_module
|
115 |
+
global dir_blended_textures, dir_anatomy, dir_background
|
116 |
+
|
117 |
+
# File path of the bodytex CSV.
|
118 |
+
bodytex_csv = "./DermSynth3D/skin3d/data/3dbodytex-1.1-highres/bodytex.csv"
|
119 |
+
bodytex_df = pd.read_csv(bodytex_csv, converters={"scan_id": lambda x: str(x)})
|
120 |
+
bodytex = BodyTexDataset(
|
121 |
+
df=bodytex_df,
|
122 |
+
dir_textures="./DermSynth3D/data/3dbodytex-1.1-highres/",
|
123 |
+
dir_annotate="./DermSynth3D/skin3d/data/3dbodytex-1.1-highres/annotations/",
|
124 |
+
)
|
125 |
+
# True to use the blended lesions, False to use the pasted lesions.
|
126 |
+
is_blend = True
|
127 |
+
background_ds = Background2d(
|
128 |
+
dir_images="./DermSynth3D/data/background/IndoorScene/",
|
129 |
+
image_filenames=None,
|
130 |
+
)
|
131 |
+
|
132 |
+
|
133 |
+
def prepare_ds_renderer(
|
134 |
+
randomize,
|
135 |
+
mesh_name,
|
136 |
+
texture_name,
|
137 |
+
num_lesion,
|
138 |
+
num_views,
|
139 |
+
dist,
|
140 |
+
elev,
|
141 |
+
azim,
|
142 |
+
light_pos,
|
143 |
+
light_ac,
|
144 |
+
light_dc,
|
145 |
+
light_sc,
|
146 |
+
mat_sh,
|
147 |
+
mat_sc,
|
148 |
+
device=DEVICE,
|
149 |
+
):
|
150 |
+
mesh_filename = get_mesh_path(mesh_name)
|
151 |
+
mesh = load_mesh_and_texture(mesh_name, texture_name, num_lesion, device)
|
152 |
+
gr.Info("Preparing for Rendering...")
|
153 |
+
mesh_renderer = MeshRendererPyTorch3D(mesh, DEVICE, config=None)
|
154 |
+
extension = f"lesion_{num_lesion}"
|
155 |
+
nevi_exists = os.path.exists(bodytex.annotation_filepath(mesh_name.split("_")[0]))
|
156 |
+
gen2d = Generate2DHelper(
|
157 |
+
mesh_filename=mesh_filename,
|
158 |
+
dir_blended_textures="./hf_demo/lesions/",
|
159 |
+
dir_anatomy="./DermSynth3D/data/bodytex_anatomy_labels/",
|
160 |
+
fitz_ds=None, # fitz_ds,
|
161 |
+
background_ds=background_ds,
|
162 |
+
device=device,
|
163 |
+
debug=True,
|
164 |
+
bodytex=bodytex,
|
165 |
+
blended_file_ext=extension, # if num_lesion > 0 else "demo",
|
166 |
+
config=None,
|
167 |
+
is_blended=is_blend,
|
168 |
+
)
|
169 |
+
blended3d = Blended3d(
|
170 |
+
mesh_filename=os.path.join(
|
171 |
+
"./DermSynth3D/data/3dbodytex-1.1-highres/",
|
172 |
+
mesh_name,
|
173 |
+
"model_highres_0_normalized.obj",
|
174 |
+
),
|
175 |
+
device=DEVICE,
|
176 |
+
dir_blended_textures=dir_blended_textures,
|
177 |
+
dir_anatomy=dir_anatomy,
|
178 |
+
extension=extension if num_lesion > 0 else "demo",
|
179 |
+
)
|
180 |
+
normal_texture = load_texture_map(
|
181 |
+
mesh, mesh_name, "No Lesion", 0, device
|
182 |
+
).maps_padded()
|
183 |
+
if num_lesion > 0:
|
184 |
+
blended_texture_image = load_texture_map(
|
185 |
+
mesh, mesh_name, "Blended Lesion", num_lesion, device
|
186 |
+
).maps_padded()
|
187 |
+
pasted_texture_image = load_texture_map(
|
188 |
+
mesh, mesh_name, "Pasted Lesion", num_lesion, device
|
189 |
+
).maps_padded()
|
190 |
+
dilated_texture_image = load_texture_map(
|
191 |
+
mesh, mesh_name, "Dilated Lesion", num_lesion, device
|
192 |
+
).maps_padded()
|
193 |
+
|
194 |
+
# texture_lesion_mask = blended3d.lesion_texture_mask(astensor=True).to(device)
|
195 |
+
# non_skin_texture_mask = blended3d.nonskin_texture_mask(astensor=True).to(device)
|
196 |
+
# vertices_to_anatomy = blended3d.vertices_to_anatomy()
|
197 |
+
# mesh_renderer.raster_settings = raster_settings
|
198 |
+
renderer, cameras, lights, materials = set_rendering_params(
|
199 |
+
randomize,
|
200 |
+
1, # num_views,
|
201 |
+
dist,
|
202 |
+
elev,
|
203 |
+
azim,
|
204 |
+
light_pos,
|
205 |
+
light_ac,
|
206 |
+
light_dc,
|
207 |
+
light_sc,
|
208 |
+
mat_sh,
|
209 |
+
mat_sc,
|
210 |
+
)
|
211 |
+
# mesh_renderer.mesh = mesh
|
212 |
+
# mesh_renderer.cameras = cameras
|
213 |
+
# mesh_renderer.lights = lights
|
214 |
+
# mesh_renderer.materials = materials
|
215 |
+
# mesh_renderer.renderer = renderer
|
216 |
+
gr.Info("Successfully prepared renderer.")
|
217 |
+
# render normal images
|
218 |
+
gr.Info("Rendering Images...")
|
219 |
+
# if num_views > 1:
|
220 |
+
# mesh_renderer.mesh = mesh.extend(num_views)
|
221 |
+
gr.Info(f"Rendering {num_views} views on {DEVICE}. Please wait...")
|
222 |
+
img_count = 0
|
223 |
+
view2d = []
|
224 |
+
depth2d = []
|
225 |
+
anatomy2d = []
|
226 |
+
seg2d = []
|
227 |
+
view_size = (224, 224)
|
228 |
+
while img_count < num_views:
|
229 |
+
if randomize:
|
230 |
+
gr.Info("Finding suitable parameters...")
|
231 |
+
success = gen2d.randomize_parameters(config=None)
|
232 |
+
if not success:
|
233 |
+
gr.Info("Could not find suitable parameters. Trying again.")
|
234 |
+
continue
|
235 |
+
else:
|
236 |
+
raster_settings = RasterizationSettings(
|
237 |
+
image_size=view_size[0],
|
238 |
+
blur_radius=0.0,
|
239 |
+
faces_per_pixel=1,
|
240 |
+
# max_faces_per_bin=100,
|
241 |
+
# bin_size=0,
|
242 |
+
perspective_correct=True,
|
243 |
+
)
|
244 |
+
gen2d.mesh_renderer.cameras = cameras
|
245 |
+
gen2d.mesh_renderer.lights = lights
|
246 |
+
gen2d.mesh_renderer.materials = materials
|
247 |
+
gen2d.mesh_renderer.raster_settings = raster_settings
|
248 |
+
gen2d.mesh_renderer.initialize_renderer()
|
249 |
+
gr.Info("Rasterization in progress...")
|
250 |
+
gen2d.mesh_renderer.compute_fragments()
|
251 |
+
gr.Info("Successfully rasterized.")
|
252 |
+
paste_img, target = gen2d.render_image_and_target(paste_lesion=True)
|
253 |
+
if paste_img is None:
|
254 |
+
gr.Info(
|
255 |
+
"***Not enough skin or unable to paste lesion. Skipping and Retrying."
|
256 |
+
)
|
257 |
+
print("***Not enough skin or unable to paste lesion. Skipping.")
|
258 |
+
continue
|
259 |
+
paste_img = (paste_img * 255).astype(np.uint8)
|
260 |
+
depth_view = target[:, :, 4]
|
261 |
+
depth_img = (depth_view - depth_view.min()) / (
|
262 |
+
depth_view.max() - depth_view.min()
|
263 |
+
)
|
264 |
+
depth_img = (depth_img * 255).astype(np.uint8)
|
265 |
+
view2d.append(paste_img)
|
266 |
+
depth2d.append(depth_img)
|
267 |
+
anatomy2d.append(target[:, :, 5])
|
268 |
+
seg2d.append(target[:, :, 3])
|
269 |
+
gr.Info(f"Successfully rendered {img_count+1}/{num_views} image+annotations.")
|
270 |
+
img_count += 1
|
271 |
+
return view2d, depth2d, anatomy2d, seg2d
|
272 |
+
|
273 |
+
# mesh_renderer.compute_fragments()
|
274 |
+
# view2d = mesh_renderer.render_view(asnumpy=True, asRGB=True)
|
275 |
+
# gr.Info("Successfully rendered images.")
|
276 |
+
# gr.Info("Preparing annotations...")
|
277 |
+
# # breakpoint()
|
278 |
+
# pix2face = torch.from_numpy(mesh_renderer.pixels_to_face()).to(
|
279 |
+
# mesh_renderer.mesh.device
|
280 |
+
# )
|
281 |
+
# pix2vert = torch.stack(
|
282 |
+
# [a[i] for a, i in zip(mesh_renderer.mesh.faces_padded().squeeze(), pix2face)]
|
283 |
+
# )
|
284 |
+
# pix2vert = pix2vert.detach().cpu().numpy()
|
285 |
+
# anatomy_image = [
|
286 |
+
# vertices_to_anatomy[pix2vert[i]] * mesh_renderer.body_mask()
|
287 |
+
# for i in range(num_views)
|
288 |
+
# ]
|
289 |
+
# anatomy_image = np.stack(anatomy_image)
|
290 |
+
|
291 |
+
# anatomy_image = mesh_renderer.anatomy_image(vertices_to_anatomy)
|
292 |
+
# depth_img = mesh_renderer.depth_view(asnumpy=True)
|
293 |
+
# mesh_renderer.set_texture_image(texture_lesion_mask[:, :, np.newaxis])
|
294 |
+
# mask2d = mesh_renderer.render_view(asnumpy=True, asRGB=True)
|
295 |
+
# lesion_mask = mesh_renderer.lesion_mask(mask2d[:, :, 0], lesion_mask_id=None)
|
296 |
+
# # skin mask
|
297 |
+
# mesh_renderer.set_texture_image(non_skin_texture_mask)
|
298 |
+
# nonskin_mask = mesh_renderer.render_view(asnumpy=True, asRGB=True)
|
299 |
+
# skin_mask = mesh_renderer.skin_mask(nonskin_mask[:, :, 0] > 0.5)
|
300 |
+
# segmentation_mask = make_masks(lesion_mask, skin_mask)
|
301 |
+
# gr.Info("Successfully prepared annotations.")
|
302 |
+
# print(view2d.shape, anatomy_image.shape, depth_img.shape, segmentation_mask.shape)
|
303 |
+
# convert anatomy image with labels for each pixel to an image with RGB values
|
304 |
+
# map labels to pixels
|
305 |
+
|
306 |
+
# return (
|
307 |
+
# view2d,
|
308 |
+
# anatomy_image,
|
309 |
+
# depth_img,
|
310 |
+
# skin_mask,
|
311 |
+
# ) # segmentation_mask
|
312 |
+
|
313 |
+
|
314 |
+
# define the list of all the examples
|
315 |
+
def get_examples():
|
316 |
+
# setup_paths()
|
317 |
+
# get mesh names from here
|
318 |
+
mesh_names = globals()["mesh_names"]
|
319 |
+
# get the textures
|
320 |
+
textures = ["No Lesion", "Pasted Lesion", "Blended Lesion", "Dilated Lesion"]
|
321 |
+
lesions = [1, 2, 5, 10]
|
322 |
+
examples = []
|
323 |
+
for mesh in mesh_names:
|
324 |
+
for texture in textures:
|
325 |
+
for lesion in lesions:
|
326 |
+
if texture == "No Lesion":
|
327 |
+
# examples.append([mesh, texture, 0, 4, True])
|
328 |
+
examples.append([mesh, texture, 0])
|
329 |
+
break
|
330 |
+
# examples.append([mesh, texture, lesion, 4, True])
|
331 |
+
examples.append([mesh, texture, lesion])
|
332 |
+
return examples
|
333 |
+
|
334 |
+
|
335 |
+
import tempfile
|
336 |
+
|
337 |
+
|
338 |
+
def get_trimesh_attrs(mesh_name, tex_name, num_lesion=1):
|
339 |
+
mesh_path = get_mesh_path(mesh_name)
|
340 |
+
texture_path = get_texture_module(tex_name)(mesh_name, num_lesion)
|
341 |
+
texture_img = Image.open(texture_path).convert("RGB")
|
342 |
+
tri_mesh = trimesh.load(mesh_path)
|
343 |
+
|
344 |
+
angle = -math.pi / 2
|
345 |
+
direction = [0, 1, 0]
|
346 |
+
center = [0, 0, 0]
|
347 |
+
rot_matrix = tf.rotation_matrix(angle, direction, center)
|
348 |
+
tri_mesh = tri_mesh.apply_transform(rot_matrix)
|
349 |
+
tri_mesh.apply_transform(tf.rotation_matrix(math.pi, [0, 0, 1], [-1, -1, -1]))
|
350 |
+
|
351 |
+
verts, faces = tri_mesh.vertices, tri_mesh.faces
|
352 |
+
uvs = tri_mesh.visual.uv
|
353 |
+
material = trimesh.visual.texture.SimpleMaterial(image=texture_img)
|
354 |
+
vis = trimesh.visual.TextureVisuals(uv=uvs, material=material, image=texture_img)
|
355 |
+
tri_mesh.visual = vis
|
356 |
+
colors = tri_mesh.visual.to_color()
|
357 |
+
vc = colors.vertex_colors # / 255.0
|
358 |
+
# timg = tri_mesh.visual.material.image
|
359 |
+
|
360 |
+
return verts, faces, vc, mesh_name
|
361 |
+
|
362 |
+
|
363 |
+
def plotly_image(image):
|
364 |
+
fig = go.Figure()
|
365 |
+
fig.add_trace(go.Image(z=image))
|
366 |
+
fig.update_layout(
|
367 |
+
width=view_width,
|
368 |
+
height=view_height,
|
369 |
+
margin=dict(l=0, r=0, b=0, t=0, pad=0),
|
370 |
+
paper_bgcolor="rgba(0,0,0,0)",
|
371 |
+
plot_bgcolor="rgba(0,0,0,0)",
|
372 |
+
)
|
373 |
+
fig.update_xaxes(showticklabels=False)
|
374 |
+
fig.update_yaxes(showticklabels=False)
|
375 |
+
fig.update_traces(hoverinfo="none")
|
376 |
+
return fig
|
377 |
+
|
378 |
+
|
379 |
+
def plotly_mesh(verts, faces, vc, mesh_name):
|
380 |
+
fig = go.Figure(
|
381 |
+
data=[
|
382 |
+
go.Mesh3d(
|
383 |
+
x=verts[:, 0],
|
384 |
+
y=verts[:, 1],
|
385 |
+
z=verts[:, 2],
|
386 |
+
i=faces[:, 0],
|
387 |
+
j=faces[:, 1],
|
388 |
+
k=faces[:, 2],
|
389 |
+
vertexcolor=vc,
|
390 |
+
)
|
391 |
+
]
|
392 |
+
)
|
393 |
+
fig.update_layout(scene_aspectmode="manual", scene_aspectratio=dict(x=1, y=1, z=1))
|
394 |
+
fig.update_layout(scene=dict(xaxis=dict(visible=False), yaxis=dict(visible=False)))
|
395 |
+
fig.update_layout(scene=dict(zaxis=dict(visible=False)))
|
396 |
+
fig.update_layout(scene=dict(camera=dict(up=dict(x=1, y=0, z=1))))
|
397 |
+
fig.update_layout(scene=dict(camera=dict(eye=dict(x=-2, y=-2, z=-1))))
|
398 |
+
# disable hover info
|
399 |
+
fig.update_traces(hoverinfo="none")
|
400 |
+
return fig
|
401 |
+
|
402 |
+
|
403 |
+
def load_texture_map(mesh, mesh_name, texture_name, num_lesion, device=DEVICE):
|
404 |
+
verts = mesh.verts_packed().detach().cpu().numpy()
|
405 |
+
faces = mesh.faces_packed().detach().cpu().numpy()
|
406 |
+
normals = mesh.verts_normals_packed().detach().cpu().numpy()
|
407 |
+
texture_path = get_texture_module(texture_name)(mesh_name, num_lesion)
|
408 |
+
texture_img = Image.open(texture_path).convert("RGB")
|
409 |
+
texture_tensor = torch.from_numpy(np.array(texture_img)).to(DEVICE)
|
410 |
+
tmap = TexturesUV(
|
411 |
+
maps=texture_tensor.float().to(device=mesh.device).unsqueeze(0),
|
412 |
+
verts_uvs=mesh.textures.verts_uvs_padded(),
|
413 |
+
faces_uvs=mesh.textures.faces_uvs_padded(),
|
414 |
+
)
|
415 |
+
return tmap
|
416 |
+
|
417 |
+
|
418 |
+
def load_mesh_and_texture(mesh_name, texture_name, num_lesion=1, device=DEVICE):
|
419 |
+
"""
|
420 |
+
Load a mesh and its corresponding texture.
|
421 |
+
|
422 |
+
Args:
|
423 |
+
mesh_name (str): The name of the mesh.
|
424 |
+
texture_name (str): The name of the texture module.
|
425 |
+
num_lesion (int, optional): The number of lesions. Defaults to 1.
|
426 |
+
device (torch.device, optional): The device to load the mesh and texture on. Defaults to DEVICE.
|
427 |
+
|
428 |
+
Returns:
|
429 |
+
new_mesh (Meshes): The loaded mesh with texture.
|
430 |
+
"""
|
431 |
+
mesh_path = get_mesh_path(mesh_name)
|
432 |
+
texture_path = get_texture_module(texture_name)(mesh_name, num_lesion)
|
433 |
+
gr.Info("Loading mesh and texture...")
|
434 |
+
mesh = load_objs_as_meshes([mesh_path], device=device)
|
435 |
+
tmap = load_texture_map(mesh, mesh_name, texture_name, num_lesion, device)
|
436 |
+
new_mesh = Meshes(
|
437 |
+
verts=mesh.verts_padded(), faces=mesh.faces_padded(), textures=tmap
|
438 |
+
)
|
439 |
+
return new_mesh
|
440 |
+
|
441 |
+
|
442 |
+
def setup_cameras(dist, elev, azim, device=DEVICE):
|
443 |
+
gr.Info("Setting up cameras...")
|
444 |
+
R, T = look_at_view_transform(dist, elev, azim, degrees=True)
|
445 |
+
cameras = FoVPerspectiveCameras(device=device, R=R, T=T, fov=30.0, znear=0.01)
|
446 |
+
return cameras
|
447 |
+
|
448 |
+
|
449 |
+
def setup_lights(
|
450 |
+
light_pos, ambient_color, diffuse_color, specular_color, device=DEVICE
|
451 |
+
):
|
452 |
+
gr.Info("Setting up lights...")
|
453 |
+
lights = PointLights(
|
454 |
+
device=device,
|
455 |
+
location=light_pos,
|
456 |
+
ambient_color=ambient_color,
|
457 |
+
diffuse_color=diffuse_color,
|
458 |
+
specular_color=specular_color,
|
459 |
+
)
|
460 |
+
return lights
|
461 |
+
|
462 |
+
|
463 |
+
def setup_materials(shininess, specularity, device=DEVICE):
|
464 |
+
gr.Info("Setting up materials...")
|
465 |
+
materials = Materials(
|
466 |
+
device=device,
|
467 |
+
specular_color=specularity, # [[specularity, specularity, specularity]],
|
468 |
+
shininess=shininess.reshape(-1), # [shininess],
|
469 |
+
)
|
470 |
+
return materials
|
471 |
+
|
472 |
+
|
473 |
+
def setup_renderer(cameras, lights, materials, device=DEVICE):
|
474 |
+
global raster_settings
|
475 |
+
raster_settings = RasterizationSettings(
|
476 |
+
image_size=128,
|
477 |
+
blur_radius=0.0,
|
478 |
+
faces_per_pixel=1,
|
479 |
+
# max_faces_per_bin=100,
|
480 |
+
# bin_size=0,
|
481 |
+
perspective_correct=True,
|
482 |
+
)
|
483 |
+
renderer = MeshRenderer(
|
484 |
+
rasterizer=MeshRasterizer(cameras=cameras, raster_settings=raster_settings),
|
485 |
+
shader=SoftPhongShader(
|
486 |
+
device=device, cameras=cameras, lights=lights, materials=materials
|
487 |
+
),
|
488 |
+
)
|
489 |
+
return renderer
|
490 |
+
|
491 |
+
|
492 |
+
def render_images(renderer, mesh, lights, cameras, materials, nviews, device=DEVICE):
|
493 |
+
meshes = mesh.extend(nviews)
|
494 |
+
gr.Info("Rendering Images...")
|
495 |
+
images = renderer(meshes, lights=lights, cameras=cameras, materials=materials)
|
496 |
+
gr.Info("Successfully rendered images.")
|
497 |
+
images = images[..., :3]
|
498 |
+
images = (images - images.min()) / (images.max() - images.min())
|
499 |
+
return images
|
500 |
+
fragments = MeshRasterizer(cameras=cameras, raster_settings=raster_settings)(meshes)
|
501 |
+
# print(images.shape)
|
502 |
+
# breakpoint()
|
503 |
+
return images
|
504 |
+
|
505 |
+
|
506 |
+
def randomize_view_params(randomize, num_views):
|
507 |
+
dist = torch.rand(num_views).uniform_(0.0, 10.0)
|
508 |
+
elev = torch.rand(num_views).uniform_(-90, 90)
|
509 |
+
azim = torch.rand(num_views).uniform_(-90, 90)
|
510 |
+
light_pos = torch.rand(num_views, 3).uniform_(0.0, 2.0)
|
511 |
+
light_ac = torch.rand(num_views, 3).uniform_(0.0, 1.0)
|
512 |
+
light_dc = torch.rand(num_views, 3).uniform_(0.0, 1.0)
|
513 |
+
light_sc = torch.rand(num_views, 3).uniform_(0.0, 1.0)
|
514 |
+
mat_sh = torch.rand(num_views, 1).uniform_(0, 100)
|
515 |
+
mat_sc = torch.rand(num_views, 3).uniform_(0.0, 1.0)
|
516 |
+
gr.Info("Randomized view parameters...")
|
517 |
+
return (
|
518 |
+
dist,
|
519 |
+
elev,
|
520 |
+
azim,
|
521 |
+
light_pos,
|
522 |
+
light_ac,
|
523 |
+
light_dc,
|
524 |
+
light_sc,
|
525 |
+
mat_sh,
|
526 |
+
mat_sc,
|
527 |
+
)
|
528 |
+
|
529 |
+
|
530 |
+
def sample_camera_params(num_views, dist, elev, azim):
|
531 |
+
gr.Info("Setting up cameras...")
|
532 |
+
dist = torch.linspace(dist - num_views // 2, dist + num_views // 2, num_views)
|
533 |
+
elev = torch.linspace(elev - num_views // 2, elev + num_views // 2, num_views)
|
534 |
+
azim = torch.linspace(azim - num_views // 2, azim + num_views // 2, num_views)
|
535 |
+
cameras = setup_cameras(dist, elev, azim)
|
536 |
+
|
537 |
+
return cameras
|
538 |
+
|
539 |
+
|
540 |
+
def sample_light_params(num_views, light_pos, light_ac, light_dc, light_sc):
|
541 |
+
gr.Info("Setting up lights...")
|
542 |
+
light_pos = (
|
543 |
+
torch.linspace(
|
544 |
+
light_pos - num_views // 2, light_pos + num_views // 2, num_views
|
545 |
+
)
|
546 |
+
.reshape(-1, 1)
|
547 |
+
.repeat(1, 3)
|
548 |
+
)
|
549 |
+
light_ac = (
|
550 |
+
torch.linspace(light_ac - num_views // 2, light_ac + num_views // 2, num_views)
|
551 |
+
.reshape(-1, 1)
|
552 |
+
.repeat(1, 3)
|
553 |
+
)
|
554 |
+
light_dc = (
|
555 |
+
torch.linspace(light_dc - num_views // 2, light_dc + num_views // 2, num_views)
|
556 |
+
.reshape(-1, 1)
|
557 |
+
.repeat(1, 3)
|
558 |
+
)
|
559 |
+
light_sc = (
|
560 |
+
torch.linspace(light_sc - num_views // 2, light_sc + num_views // 2, num_views)
|
561 |
+
.reshape(-1, 1)
|
562 |
+
.repeat(1, 3)
|
563 |
+
)
|
564 |
+
lights = setup_lights(light_pos, light_ac, light_dc, light_sc)
|
565 |
+
return lights
|
566 |
+
|
567 |
+
|
568 |
+
def sample_material_params(num_views, mat_sh, mat_sc):
|
569 |
+
gr.Info("Setting up materials...")
|
570 |
+
mat_sh = (
|
571 |
+
torch.linspace(mat_sh - num_views // 2, mat_sh + num_views // 2, num_views)
|
572 |
+
.reshape(-1, 1)
|
573 |
+
.repeat(1, 1)
|
574 |
+
)
|
575 |
+
mat_sc = (
|
576 |
+
torch.linspace(mat_sc - num_views // 2, mat_sc + num_views // 2, num_views)
|
577 |
+
.reshape(-1, 1)
|
578 |
+
.repeat(1, 3)
|
579 |
+
)
|
580 |
+
materials = setup_materials(mat_sh, mat_sc)
|
581 |
+
return materials
|
582 |
+
|
583 |
+
|
584 |
+
def set_rendering_params(
|
585 |
+
randomize,
|
586 |
+
num_views,
|
587 |
+
dist,
|
588 |
+
elev,
|
589 |
+
azim,
|
590 |
+
light_pos,
|
591 |
+
light_ac,
|
592 |
+
light_dc,
|
593 |
+
light_sc,
|
594 |
+
mat_sh,
|
595 |
+
mat_sc,
|
596 |
+
):
|
597 |
+
if randomize:
|
598 |
+
(
|
599 |
+
dist,
|
600 |
+
elev,
|
601 |
+
azim,
|
602 |
+
light_pos,
|
603 |
+
light_ac,
|
604 |
+
light_dc,
|
605 |
+
light_sc,
|
606 |
+
mat_sh,
|
607 |
+
mat_sc,
|
608 |
+
) = randomize_view_params(randomize, num_views)
|
609 |
+
cameras = setup_cameras(dist, elev, azim)
|
610 |
+
lights = setup_lights(light_pos, light_ac, light_dc, light_sc)
|
611 |
+
materials = setup_materials(mat_sh, mat_sc)
|
612 |
+
else:
|
613 |
+
cameras = sample_camera_params(num_views, dist, elev, azim)
|
614 |
+
lights = sample_light_params(num_views, light_pos, light_ac, light_dc, light_sc)
|
615 |
+
materials = sample_material_params(num_views, mat_sh, mat_sc)
|
616 |
+
|
617 |
+
renderer = setup_renderer(cameras, lights, materials)
|
618 |
+
return renderer, cameras, lights, materials
|
619 |
+
|
620 |
+
|
621 |
+
def process_examples(mesh_name, tex_name, n_lesion):
|
622 |
+
mesh_path = get_mesh_path(mesh_name)
|
623 |
+
texture_path = get_texture_module(tex_name)(mesh_name, n_lesion)
|
624 |
+
mesh_to_view = plotly_mesh(*get_trimesh_attrs(mesh_name, tex_name, n_lesion))
|
625 |
+
# mesh = load_mesh_and_texture(mesh_name, tex_name, n_lesion)
|
626 |
+
return mesh_to_view, texture_path, n_lesion
|
627 |
+
|
628 |
+
|
629 |
+
def update_plots(mesh_name, texture_name, num_lesion):
|
630 |
+
if num_lesion > 0 and texture_name == "No Lesion":
|
631 |
+
gr.Warning(
|
632 |
+
f"Cannot display '{texture_name}' texture map with {num_lesion} lesions! Please change the texture. Meanwhile, not updating the display."
|
633 |
+
)
|
634 |
+
return default_mesh_plot, default_texture, num_lesion
|
635 |
+
elif num_lesion == 0 and texture_name != "No Lesion":
|
636 |
+
go.Warning(
|
637 |
+
f"Cannot display '{texture_name}' texture map with {num_lesion} lesions! Please increase the number of lesions."
|
638 |
+
)
|
639 |
+
return default_mesh_plot, default_texture, num_lesion
|
640 |
+
mesh_path = get_mesh_path(mesh_name)
|
641 |
+
texture_path = get_texture_module(texture_name)(mesh_name, num_lesion)
|
642 |
+
mesh_to_view = plotly_mesh(*get_trimesh_attrs(mesh_name, texture_name, num_lesion))
|
643 |
+
gr.Info("Successfully updated mesh and texture.")
|
644 |
+
return mesh_to_view, texture_path, num_lesion
|
645 |
+
|
646 |
+
|
647 |
+
def run_demo():
|
648 |
+
# get the defined examples
|
649 |
+
all_examples = get_examples()
|
650 |
+
|
651 |
+
mesh_block = gr.Plot(
|
652 |
+
label="Selected Mesh",
|
653 |
+
value=default_mesh_plot,
|
654 |
+
# scale=1,
|
655 |
+
)
|
656 |
+
texture_block = gr.Image(
|
657 |
+
value=default_texture,
|
658 |
+
type="pil",
|
659 |
+
image_mode="RGB",
|
660 |
+
height="auto",
|
661 |
+
width="auto",
|
662 |
+
label="Selected Texture",
|
663 |
+
)
|
664 |
+
num_lesions = gr.Radio(
|
665 |
+
choices=[0, 1, 2, 5, 10],
|
666 |
+
label="Number of Lesions",
|
667 |
+
value=0,
|
668 |
+
interactive=True,
|
669 |
+
)
|
670 |
+
num_views = gr.Slider(2, 32, 4, label="Number of Views", step=2, interactive=True)
|
671 |
+
randomize = gr.Checkbox(
|
672 |
+
label="Randomize View Parameters", value=True, interactive=True
|
673 |
+
)
|
674 |
+
render_button = gr.Button("Render Views")
|
675 |
+
|
676 |
+
select_mesh = gr.Dropdown(
|
677 |
+
choices=mesh_names,
|
678 |
+
value=mesh_names[0],
|
679 |
+
interactive=True,
|
680 |
+
label="Input Mesh",
|
681 |
+
info="Select the mesh to render",
|
682 |
+
)
|
683 |
+
select_texture = gr.Dropdown(
|
684 |
+
choices=["No Lesion", "Pasted Lesion", "Blended Lesion", "Dilated Lesion"],
|
685 |
+
value="No Lesion",
|
686 |
+
interactive=True,
|
687 |
+
label="Input Texture",
|
688 |
+
info="Select the texture to use for the mesh.",
|
689 |
+
)
|
690 |
+
# compose demo layout and data flow
|
691 |
+
with gr.Blocks(
|
692 |
+
title=_TITLE, analytics_enabled=True, theme=gr.themes.Base()
|
693 |
+
) as demo:
|
694 |
+
with gr.Row():
|
695 |
+
with gr.Column(scale=1):
|
696 |
+
gr.Markdown(f"# {_TITLE}")
|
697 |
+
gr.Markdown(_DESCRIPTION)
|
698 |
+
|
699 |
+
# User input panel
|
700 |
+
with gr.Row(variant="panel"):
|
701 |
+
with gr.Column(scale=1):
|
702 |
+
select_mesh.render()
|
703 |
+
select_texture.render()
|
704 |
+
num_lesions.render()
|
705 |
+
num_views.render()
|
706 |
+
randomize.render()
|
707 |
+
|
708 |
+
with gr.Column(scale=1):
|
709 |
+
mesh_block.render()
|
710 |
+
with gr.Column(scale=1):
|
711 |
+
texture_block.render()
|
712 |
+
|
713 |
+
gr.on(
|
714 |
+
triggers=[
|
715 |
+
select_mesh.change,
|
716 |
+
select_texture.change,
|
717 |
+
num_lesions.change,
|
718 |
+
],
|
719 |
+
inputs=[select_mesh, select_texture, num_lesions],
|
720 |
+
outputs=[mesh_block, texture_block, num_lesions],
|
721 |
+
fn=update_plots,
|
722 |
+
)
|
723 |
+
|
724 |
+
# @gr.on(
|
725 |
+
# inputs=[
|
726 |
+
# select_mesh,
|
727 |
+
# select_texture,
|
728 |
+
# num_lesions,
|
729 |
+
# ],
|
730 |
+
# outputs=[
|
731 |
+
# mesh_block,
|
732 |
+
# texture_block,
|
733 |
+
# num_lesions,
|
734 |
+
# ],
|
735 |
+
# triggers=[
|
736 |
+
# select_mesh.change,
|
737 |
+
# select_texture.change,
|
738 |
+
# num_lesions.change,
|
739 |
+
# ],
|
740 |
+
# )
|
741 |
+
# def update(m, t, l):
|
742 |
+
# return update_plots(m, t, l)
|
743 |
+
|
744 |
+
# rendering choices
|
745 |
+
with gr.Row(variant="panel"):
|
746 |
+
with gr.Column(scale=1):
|
747 |
+
render_button.render()
|
748 |
+
with gr.Column(scale=1):
|
749 |
+
with gr.Accordion("Configure View Parameters", open=False):
|
750 |
+
# setup cameras
|
751 |
+
with gr.Accordion("Camera Parameters", open=False):
|
752 |
+
dist = gr.Slider(
|
753 |
+
minimum=0.0,
|
754 |
+
maximum=10.0,
|
755 |
+
value=0.5,
|
756 |
+
step=0.5,
|
757 |
+
interactive=True,
|
758 |
+
label="Distance",
|
759 |
+
)
|
760 |
+
elev = gr.Slider(
|
761 |
+
label="Elevation",
|
762 |
+
interactive=True,
|
763 |
+
minimum=-90,
|
764 |
+
maximum=90,
|
765 |
+
value=0,
|
766 |
+
step=10,
|
767 |
+
)
|
768 |
+
azim = gr.Slider(
|
769 |
+
label="Azimuth",
|
770 |
+
interactive=True,
|
771 |
+
minimum=-90,
|
772 |
+
maximum=90,
|
773 |
+
value=90,
|
774 |
+
step=10,
|
775 |
+
)
|
776 |
+
# setup lights
|
777 |
+
with gr.Accordion("Lighting Parameters", open=False):
|
778 |
+
light_pos = gr.Slider(
|
779 |
+
label="Light Position",
|
780 |
+
interactive=True,
|
781 |
+
minimum=0.0,
|
782 |
+
maximum=2.0,
|
783 |
+
value=0.5,
|
784 |
+
step=0.1,
|
785 |
+
)
|
786 |
+
light_ac = gr.Slider(
|
787 |
+
label="Ambient Color",
|
788 |
+
minimum=0.0,
|
789 |
+
maximum=1.0,
|
790 |
+
interactive=True,
|
791 |
+
value=0.5,
|
792 |
+
step=0.1,
|
793 |
+
)
|
794 |
+
light_dc = gr.Slider(
|
795 |
+
label="Diffuse Color",
|
796 |
+
minimum=0.0,
|
797 |
+
maximum=1.0,
|
798 |
+
interactive=True,
|
799 |
+
value=0.5,
|
800 |
+
step=0.1,
|
801 |
+
)
|
802 |
+
light_sc = gr.Slider(
|
803 |
+
label="Specular Color",
|
804 |
+
minimum=0.0,
|
805 |
+
maximum=1.0,
|
806 |
+
interactive=True,
|
807 |
+
value=0.5,
|
808 |
+
step=0.1,
|
809 |
+
)
|
810 |
+
# setup material parameters
|
811 |
+
with gr.Accordion("Material Parameters", open=False):
|
812 |
+
mat_sh = gr.Slider(
|
813 |
+
label="Shininess",
|
814 |
+
interactive=True,
|
815 |
+
minimum=0,
|
816 |
+
maximum=100,
|
817 |
+
value=50,
|
818 |
+
step=10,
|
819 |
+
)
|
820 |
+
mat_sc = gr.Slider(
|
821 |
+
label="Specularity",
|
822 |
+
minimum=0.0,
|
823 |
+
interactive=True,
|
824 |
+
maximum=1.0,
|
825 |
+
value=0.5,
|
826 |
+
step=0.1,
|
827 |
+
)
|
828 |
+
|
829 |
+
update_view_btn = gr.Button("Update View Parameters")
|
830 |
+
|
831 |
+
gr.on(
|
832 |
+
triggers=[
|
833 |
+
update_view_btn.click,
|
834 |
+
dist.change,
|
835 |
+
elev.change,
|
836 |
+
azim.change,
|
837 |
+
light_pos.change,
|
838 |
+
light_ac.change,
|
839 |
+
light_dc.change,
|
840 |
+
light_sc.change,
|
841 |
+
mat_sh.change,
|
842 |
+
mat_sc.change,
|
843 |
+
],
|
844 |
+
inputs=[randomize],
|
845 |
+
outputs=[randomize],
|
846 |
+
fn=lambda x: False,
|
847 |
+
show_progress="hidden",
|
848 |
+
queue=False,
|
849 |
+
scroll_to_output=True,
|
850 |
+
)
|
851 |
+
# rendered views panel
|
852 |
+
with gr.Row(variant="panel"):
|
853 |
+
render_block = gr.Gallery(
|
854 |
+
label="Rendered Views", columns=4, height="auto", object_fit="contain"
|
855 |
+
)
|
856 |
+
|
857 |
+
@gr.on(
|
858 |
+
triggers=[render_button.click],
|
859 |
+
inputs=[
|
860 |
+
randomize,
|
861 |
+
select_mesh,
|
862 |
+
select_texture,
|
863 |
+
num_lesions,
|
864 |
+
num_views,
|
865 |
+
dist,
|
866 |
+
elev,
|
867 |
+
azim,
|
868 |
+
light_pos,
|
869 |
+
light_ac,
|
870 |
+
light_dc,
|
871 |
+
light_sc,
|
872 |
+
mat_sh,
|
873 |
+
mat_sc,
|
874 |
+
],
|
875 |
+
outputs=[render_block],
|
876 |
+
)
|
877 |
+
def render_views(
|
878 |
+
randomize,
|
879 |
+
select_mesh,
|
880 |
+
select_texture,
|
881 |
+
num_lesions,
|
882 |
+
num_views,
|
883 |
+
dist,
|
884 |
+
elev,
|
885 |
+
azim,
|
886 |
+
light_pos,
|
887 |
+
light_ac,
|
888 |
+
light_dc,
|
889 |
+
light_sc,
|
890 |
+
mat_sh,
|
891 |
+
mat_sc,
|
892 |
+
):
|
893 |
+
renderer, cameras, lights, materials = set_rendering_params(
|
894 |
+
randomize,
|
895 |
+
num_views,
|
896 |
+
dist,
|
897 |
+
elev,
|
898 |
+
azim,
|
899 |
+
light_pos,
|
900 |
+
light_ac,
|
901 |
+
light_dc,
|
902 |
+
light_sc,
|
903 |
+
mat_sh,
|
904 |
+
mat_sc,
|
905 |
+
)
|
906 |
+
# gr.Info("Loading mesh and texture...")
|
907 |
+
# mesh = load_mesh_and_texture(select_mesh, select_texture, num_lesions)
|
908 |
+
# cameras
|
909 |
+
# images = render_images(
|
910 |
+
# renderer, mesh, lights, cameras, materials, num_views
|
911 |
+
# )
|
912 |
+
# return [_ for _ in images.detach().cpu().numpy()]
|
913 |
+
view2d, anatomy, depth, segmentation = prepare_ds_renderer(
|
914 |
+
randomize,
|
915 |
+
select_mesh,
|
916 |
+
select_texture,
|
917 |
+
num_lesions,
|
918 |
+
num_views,
|
919 |
+
dist,
|
920 |
+
elev,
|
921 |
+
azim,
|
922 |
+
light_pos,
|
923 |
+
light_ac,
|
924 |
+
light_dc,
|
925 |
+
light_sc,
|
926 |
+
mat_sh,
|
927 |
+
mat_sc,
|
928 |
+
)
|
929 |
+
return view2d
|
930 |
+
|
931 |
+
# examples panel when the iuser does not want to input
|
932 |
+
with gr.Row(variant="panel"):
|
933 |
+
with gr.Column(scale=1):
|
934 |
+
gr.Examples(
|
935 |
+
examples=all_examples,
|
936 |
+
inputs=[
|
937 |
+
select_mesh,
|
938 |
+
select_texture,
|
939 |
+
num_lesions,
|
940 |
+
],
|
941 |
+
outputs=[
|
942 |
+
mesh_block,
|
943 |
+
texture_block,
|
944 |
+
num_lesions,
|
945 |
+
],
|
946 |
+
cache_examples=False,
|
947 |
+
fn=update_plots,
|
948 |
+
label="Meshes and Textures for Demo (Click to start)",
|
949 |
+
)
|
950 |
+
|
951 |
+
demo.queue(max_size=10)
|
952 |
+
demo.launch(
|
953 |
+
share=True,
|
954 |
+
max_threads=mp.cpu_count(),
|
955 |
+
show_error=True,
|
956 |
+
show_api=False,
|
957 |
+
)
|
958 |
+
|
959 |
+
|
960 |
+
def get_texture_module(tex_type):
|
961 |
+
if tex_type == "No Lesion":
|
962 |
+
return get_no_lesion_path
|
963 |
+
elif tex_type == "Pasted Lesion":
|
964 |
+
return get_pasted_lesion_path
|
965 |
+
elif tex_type == "Blended Lesion":
|
966 |
+
return get_blended_lesion_path
|
967 |
+
elif tex_type == "Dilated Lesion":
|
968 |
+
return get_dilated_lesion_path
|
969 |
+
else:
|
970 |
+
raise ValueError(f"Texture type {tex_type} not supported!")
|
971 |
+
|
972 |
+
|
973 |
+
if __name__ == "__main__":
|
974 |
+
# setup_paths()
|
975 |
+
mesh_paths = glob("./DermSynth3D//data/3dbodytex-1.1-highres/*/*.obj")
|
976 |
+
mesh_names = [os.path.basename(os.path.dirname(x)) for x in mesh_paths]
|
977 |
+
# get the textures
|
978 |
+
all_textures = glob("./DermSynth3D//data/3dbodytex-1.1-highres/*/*.png")
|
979 |
+
dir_blended_textures = "./hf_demo/lesions/"
|
980 |
+
dir_anatomy = "./DermSynth3D/data/bodytex_anatomy_labels/"
|
981 |
+
dir_background = "./DermSynth3D/data/background/IndoorScene/"
|
982 |
+
get_no_lesion_path = lambda x, y: os.path.join(
|
983 |
+
"./DermSynth3D/data/3dbodytex-1.1-highres", x, "model_highres_0_normalized.png"
|
984 |
+
)
|
985 |
+
get_mesh_path = lambda x: os.path.join(
|
986 |
+
"./DermSynth3D/data/3dbodytex-1.1-highres", x, "model_highres_0_normalized.obj"
|
987 |
+
)
|
988 |
+
# get the textures with the lesions
|
989 |
+
get_mask_path = lambda x: os.path.join(
|
990 |
+
"./hf_demo/lesions/", x, "model_highres_0_normalized_mask.png"
|
991 |
+
)
|
992 |
+
get_dilated_lesion_path = lambda x, y: os.path.join(
|
993 |
+
"./hf_demo/lesions/",
|
994 |
+
x,
|
995 |
+
f"model_highres_0_normalized_dilated_lesion_{y}.png",
|
996 |
+
)
|
997 |
+
get_blended_lesion_path = lambda x, y: os.path.join(
|
998 |
+
"./hf_demo/lesions/",
|
999 |
+
x,
|
1000 |
+
f"model_highres_0_normalized_blended_lesion_{y}.png",
|
1001 |
+
)
|
1002 |
+
get_pasted_lesion_path = lambda x, y: os.path.join(
|
1003 |
+
"./hf_demo/lesions/",
|
1004 |
+
x,
|
1005 |
+
f"model_highres_0_normalized_pasted_lesion_{y}.png",
|
1006 |
+
)
|
1007 |
+
default_mesh_plot = plotly_mesh(*get_trimesh_attrs(mesh_names[0], "No Lesion", 0))
|
1008 |
+
default_texture = Image.open(all_textures[0]).convert("RGB").resize((512, 512))
|
1009 |
+
new_values = {
|
1010 |
+
"default_mesh_plot": default_mesh_plot,
|
1011 |
+
"default_texture": default_texture,
|
1012 |
+
}
|
1013 |
+
globals().update(new_values)
|
1014 |
+
run_demo()
|
hf_demo/lesions/006-f-run/lesion_dilated_mask_demo.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_dilated_mask_latest.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_1.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_10.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_15.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_2.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_30.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_dilated_mask_lesion_5.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_mask_latest.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_mask_lesion_0.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_mask_lesion_1.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_mask_lesion_10.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_mask_lesion_15.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_mask_lesion_2.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_mask_lesion_30.png
ADDED
![]() |
hf_demo/lesions/006-f-run/lesion_mask_lesion_5.png
ADDED
![]() |
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_demo.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_latest.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_1.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_10.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_15.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_2.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_30.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_blended_lesion_5.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_demo.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_latest.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_1.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_10.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_15.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_2.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_30.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_dilated_lesion_5.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_lesion_0.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_mask.png
ADDED
![]() |
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_demo.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_latest.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_1.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_10.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_15.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_2.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_30.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/006-f-run/model_highres_0_normalized_pasted_lesion_5.png
ADDED
![]() |
Git LFS Details
|
hf_demo/lesions/221-m-u/lesion_dilated_mask_lesion_1.png
ADDED
![]() |
hf_demo/lesions/221-m-u/lesion_dilated_mask_lesion_10.png
ADDED
![]() |
hf_demo/lesions/221-m-u/lesion_dilated_mask_lesion_15.png
ADDED
![]() |
hf_demo/lesions/221-m-u/lesion_dilated_mask_lesion_2.png
ADDED
![]() |