* - Use staged container builds to improve caching and reduce size
- Image size reduced from 8 GB to 1.6ish
- Switched from Make to Ninja for faster builds that do not hog processor
- Removed unneded dependencies
- Added to .dockerignore
- Readme for docker stuff
- Staged Builds
- Docker's overlay FS means that `rm`ing files does not reduce size
- Once build artifacts are build, the build dependencies are no longer needed
- Both of these can be solved by building in a temporary image and copying
only the needed libraries in
- Leverages DESTDIR to generate a directory structure that can be just
copied onto the `/` of the filesystem
- Similarly, the data files (like models) can be downloaded ahead of time
into their own image and copied in. This saves on network IO.
- Anything in a RUN directive that is non-deterministic (e.g. downloading
a file from a link, the content of that link changes) does not cause a cache
miss, so if you need to update something RUN uses, either modify the
dockerfile or build with `--no-cache` to force a rebuild
- Switch to Ninja
- cmake can generate many types of build systems
- Ninja builds faster than GNU Make
- `make -j` has a tendency to lock up my system when building locally
- Do not need to tell ninja how many jobs to run
- .dockerignore
- Paths in .dockerignore are basically invisible to dockerd, so when dockerd
zips up the build context, all of the cruft can be ignored
- it is beneficial to docker build speed to add any large, unnecssary files
and directories to .dockerignore.
- Just remember they cannot be seen by dockerd
* removing cruft and some format fixes
* updated dockerfile to opencv 4.1.0
Docker building instructions
This image can be build with just docker, but it is highly recommend to use
docker-compose as this greatly simplifies and improves the process.
Quick start
To start with the container hosted by the repo maintainer, run
docker run -it --rm --name openface algebr/openface:latest
This will drop you into a shell with binaries such as FaceLandmarkImg. For example, try this code (in the container):
curl -o tesla.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Nicola_Tesla_LCCN2014684845.jpg/559px-Nicola_Tesla_LCCN2014684845.jpg
FaceLandmarkImg -f tesla.jpg
Then, copy the output to the host system (from host terminal):
docker cp openface:/root/processed /tmp/
cd /tmp/processed
Tip: On Ubuntu and other *nixes with X running, you can open a file directly like this:
xdg-open /tmp/processed/tesla.jpg
Building
In repo root, run docker-compose build to automatically build and tag.
There are two variables which can be used to modify the tag, $DOCKERUSER and
$DOCKERTAG. DC will automatically tag image as
${DOCKERUSER}/openface:${DOCKERTAG}
OpenFace service (in progress)
To run OpenFace like a service, you can start the container with bind mounts
in order to pass data into and out of the container easily.
$DATA_MOUNT by default is set to /tmp/openface. This can be overridden by
modifying .env file, setting it in your shell environment, or passing in
before docker-compose at runtime. Note: output will be root owner.
export DATA_MOUNT=/tmp/openface
mkdir -p $DATA_MOUNT/tesla # this is just to ensure this is writable by user
docker-compose up -d openface && sync # sync is to wait till service starts
curl -o $DATA_MOUNT/tesla.jpg \
https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Nicola_Tesla_LCCN2014684845.jpg/559px-Nicola_Tesla_LCCN2014684845.jpg
docker exec -it openface FaceLandmarkImg -f $DATA_MOUNT/tesla.jpg -out_dir $DATA_MOUNT/tesla
docker exec -it openface chown -R $UID:$UID $DATA_MOUNT # chown to current user
docker-compose down # stop service if you wish