diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3f2af7 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Tensorflow + +Docker files ready to build tensorflow and it's addons from source files. + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d1e9291 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: "3.9" +services: + tensorflow: + build: + context: ./tensorflow + dockerfile: Dockerfile + container_name: tensorflow + image: tensorflow:r2.11 + tensorflow-addons: + build: + context: ./tensorflow-addons + dockerfile: Dockerfile + container_name: tensorflow-addons + image: tensorflow-addons:r0.18 + depends_on: + - "tensorflow" diff --git a/tensorflow-addons/Dockerfile b/tensorflow-addons/Dockerfile new file mode 100644 index 0000000..5c73aee --- /dev/null +++ b/tensorflow-addons/Dockerfile @@ -0,0 +1,33 @@ +ARG UBUNTU_VERSION=latest +FROM ubuntu:${UBUNTU_VERSION} AS tfa-build +RUN apt-get update +RUN apt-get install -y python3-dev python3-pip +RUN pip install -U pip numpy wheel packaging requests opt_einsum +RUN pip install -U keras_preprocessing --no-deps + +RUN apt-get install -y apt-transport-https curl gnupg +RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel-archive-keyring.gpg +RUN mv bazel-archive-keyring.gpg /usr/share/keyrings +RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list +ARG BAZEL_VERSION=5.3.0 +RUN apt-get update && apt-get install -y bazel-${BAZEL_VERSION} +RUN ln -s /usr/bin/bazel-${BAZEL_VERSION} /usr/bin/bazel + +WORKDIR / +RUN apt-get -y install git rsync python-is-python3 +RUN git clone https://github.com/tensorflow/addons.git +WORKDIR /addons +ARG TF_ADDONS_BRANCH=r0.18 +RUN git checkout ${TF_ADDONS_BRANCH} +RUN python ./configure.py +RUN bazel build build_pip_pkg +RUN bazel-bin/build_pip_pkg artifacts + +FROM ubuntu:${UBUNTU_VERSION} AS tfa-install +ARG DEBIAN_FRONTEND=noninteractive +COPY --from=tfa-build /addons/artifacts/*.whl /wheels/ +RUN pip install /wheels/tensorflow_addons-*.whl + +RUN python3 -c "import tensorflow_addons as tfa" + +CMD ["python3"] \ No newline at end of file diff --git a/tensorflow/Dockerfile b/tensorflow/Dockerfile new file mode 100644 index 0000000..1b9f448 --- /dev/null +++ b/tensorflow/Dockerfile @@ -0,0 +1,45 @@ +ARG UBUNTU_VERSION=latest +FROM ubuntu:${UBUNTU_VERSION} AS tf-build +RUN apt-get update +RUN apt-get install -y python3-dev python3-pip +RUN pip install -U pip numpy wheel packaging requests opt_einsum +RUN pip install -U keras_preprocessing --no-deps + +RUN apt-get install -y apt-transport-https curl gnupg +RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel-archive-keyring.gpg +RUN mv bazel-archive-keyring.gpg /usr/share/keyrings +RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list +ARG BAZEL_VERSION=5.3.0 +RUN apt-get update && apt-get install -y bazel-${BAZEL_VERSION} +RUN ln -s /usr/bin/bazel-${BAZEL_VERSION} /usr/bin/bazel + +WORKDIR / +RUN apt-get -y install git + +RUN git clone https://github.com/tensorflow/tensorflow.git +WORKDIR /tensorflow +ARG TENSORFLOW_BRANCH=r2.11 +RUN git checkout ${TENSORFLOW_BRANCH} + +# CPU support configuration +RUN ./configure + +# CPU only support +RUN bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package + +# GPU support +#RUN bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package + +# Build pip whl package +RUN ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg + +FROM ubuntu:${UBUNTU_VERSION} AS tf-install +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update +RUN apt-get install -y python3 python3-pip +COPY --from=tf-build /tmp/tensorflow_pkg/*.whl wheels/ +RUN pip install /wheels/tensorflow-*.whl + +RUN python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))" + +CMD ["python3"] \ No newline at end of file