Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
90 changes: 90 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
FROM gurobi/optimizer:9.1.2

WORKDIR /opt/build

# Set opencv version and disable gui
ENV OPENCV_VERSION="4.7.0" \
QT_QPA_PLATFORM=offscreen

# Install dependencies (boost, openmp, qt, opencv, eigen, numpy)
RUN apt-get -qq update \
&& apt-get -qq install -y --no-install-recommends \
build-essential \
cmake \
git \
wget \
unzip \
yasm \
pkg-config \
python3-dev \
libswscale-dev \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libopenjp2-7-dev \
libavformat-dev \
libpq-dev \
libz-dev \
libbz2-dev \
libatlas-base-dev \
qtbase5-dev \
libboost-all-dev \
libeigen3-dev \
libomp-dev \
time \
&& pip install numpy \
&& wget -q https://github.com/opencv/opencv/archive/refs/tags/${OPENCV_VERSION}.zip -O opencv.zip \
&& unzip -qq opencv.zip -d /opt \
&& rm -rf opencv.zip \
&& cmake \
-D BUILD_TIFF=ON \
-D BUILD_opencv_java=OFF \
-D WITH_CUDA=ON \
-D WITH_OPENGL=ON \
-D WITH_OPENCL=ON \
-D WITH_IPP=ON \
-D WITH_TBB=ON \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$(python3.11 -c "import sys; print(sys.prefix)") \
-D PYTHON_EXECUTABLE=$(which python3.11) \
-D PYTHON_INCLUDE_DIR=$(python3.11 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON_PACKAGES_PATH=$(python3.11 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
/opt/opencv-${OPENCV_VERSION} \
&& make -j$(nproc) \
&& make install \
&& rm -rf /opt/build/* \
&& rm -rf /opt/opencv-${OPENCV_VERSION} \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get -qq autoremove \
&& apt-get -qq clean


COPY . /workspace/line-drawing-vectorization-polyvector-flow
WORKDIR /workspace/line-drawing-vectorization-polyvector-flow
# Install python dependencies
RUN pip install -U pip wheel \
&& pip install -r requirements.txt \
&& pip cache purge

# Install paal
RUN wget http://paal.mimuw.edu.pl/paal.zip && unzip paal.zip && mv home/paal/sources/paal/include/paal . && rm -rf home

# Fix for: https://support.gurobi.com/hc/en-us/articles/360039093112-How-do-I-resolve-undefined-reference-errors-while-linking-Gurobi-in-C-
RUN ln -s /opt/gurobi /opt/gurobi911 \
&& cd /opt/gurobi/linux64/src/build \
&& make \
&& cp /opt/gurobi/linux64/src/build/libgurobi_c++.a /opt/gurobi/linux64/lib/

# Build the vectorization algorithm
RUN mkdir build
WORKDIR /workspace/line-drawing-vectorization-polyvector-flow/build
RUN cmake -DCMAKE_BUILD_TYPE=Release .. && make -j$(nproc)
WORKDIR /workspace/line-drawing-vectorization-polyvector-flow

STOPSIGNAL SIGINT
ENTRYPOINT ["/bin/bash", "run_vectorization.sh"]
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3.9"
name: line-drawing-vectorization-polyvector-flow
services:
gpu:
build:
context: .
volumes:
- ./inputs:/workspace/line-drawing-vectorization-polyvector-flow/inputs
- ./gurobi.lic:/opt/gurobi/gurobi.lic:ro
tmpfs:
- /tmp
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
4 changes: 2 additions & 2 deletions predict_points.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ case "$(uname -s)" in

Linux)
echo 'Linux'
python prediction/usemodel.py --model prediction/best_model_checkpoint.pth --input $inputimage --output $outputpts
python prediction/usemodel.py --model prediction/best_model_checkpoint.pth --input "$inputimage" --output "$outputpts"
echo 'Done!'
;;

CYGWIN*|MINGW32*|MSYS*|MINGW*)
echo 'MS Windows'
# run python prediction
python usemodel.py --input $inputimage --output $outputpts
python usemodel.py --input "$inputimage" --output "$outputpts"
# execute polyvector with arguments ../my_inputs/alligator_cut2.png ../my_inputs/pythontest.pts

;;
Expand Down
39 changes: 38 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,51 @@ Contact me if you need code for speed benchmarks. This release was tuned for bet
}
```

## Cmake build
## Installation

### Cmake build
```bash
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
```

### Using Docker (alternative)
Requires [Docker](https://docs.docker.com/engine/install/) and [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html) (for GPU acceleration).

Retrieve a [Gurobi WLS license](https://www.gurobi.com/features/web-license-service/). This can be done by running:

```
grbgetkey
```

This will produce a `gurobi.lic` file. Place this into the repository directory.

To build the Docker image using docker compose:

```
docker compose build
```

Alternatively, build it using `docker build`:

```
docker build -t line-drawing-vectorization-polyvector-flow-gpu .
```

Then, run a Docker container based on the built image using docker compose:

```
docker compose run gpu inputs/example.png
```

Alternatively, run it using `docker run`:

```
docker run --rm -v ./gurobi.lic:/opt/gurobi/gurobi.lic:ro -v ./inputs:/workspace/line-drawing-vectorization-polyvector-flow/inputs --gpus all line-drawing-vectorization-polyvector-flow-gpu inputs/example.png
```

## Usage

Running `build/vectorize` will start vectorization on default input parameters: `inputs/example.png` and `inputs/example.pts`
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
torch==1.10
Pillow==9.2.0
scikit-image==0.19.3
matplotlib==3.5.2
20 changes: 10 additions & 10 deletions run_vectorization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

# This script runs vectorization pipeline on imagefile provided (.png or .jpg)

image=${1:-"examples/dog06.png"}
image="${1:-"examples/dog06.png"}"

ptsfile=${image//.png/_auto.pts}
svgfile=${image//.png/_result.svg}
txtfile=${image//.png/_logs.txt}
ptsfile="${image//.png/_auto.pts}"
svgfile="${image//.png/_result.svg}"
txtfile="${image//.png/_logs.txt}"

ptsfile=${ptsfile//.jpg/_auto.pts}
svgfile=${svgfile//.jpg/_result.svg}
txtfile=${txtfile//.jpg/_logs.txt}
ptsfile="${ptsfile//.jpg/_auto.pts}"
svgfile="${svgfile//.jpg/_result.svg}"
txtfile="${txtfile//.jpg/_logs.txt}"

echo $image - $ptsfile - $svgfile
echo "$image - $ptsfile - $svgfile"

bash predict_points.sh $image $ptsfile
bash predict_points.sh "$image" "$ptsfile"

build/vectorize $image $ptsfile $svgfile
build/vectorize "$image" "$ptsfile" "$svgfile"