I am trying to build a Django app that would use Keras models to make recommendations. Right now I'm trying to use one custom container that would hold both Django and Keras. Here's the Dockerfile I've written.
# myproject/docker/app/Dockerfile
FROM python:3.7-alpine # I've tried 3.5, 3.6 and 3.7
RUN apk add --no-cache postgresql-libs && \
apk add --no-cache --virtual .build-deps \
gfortran \
build-base \
freetype-dev \
libpng-dev \
openblas-dev \
postgresql-dev \
python3-dev \
wget
WORKDIR /app
COPY ./misc/requirements.txt /app/
RUN pip search tensorflow
RUN pip install tensorflow
RUN pip install -r /app/requirements.txt
COPY . /app
EXPOSE 8000
ENTRYPOINT ["exec /start.sh"]
Problem is, when I try to build app image, pip can't install tensorflow, even though pip search tensorflow lists tensorflow (1.12) in results.
$ docker-compose -f "docker/docker-compose.yml" --project-directory /path/to/myproject build
psql uses an image, skipping
redis uses an image, skipping
Building app
Step 1/12 : FROM python:3.7-alpine
3.7-alpine: Pulling from library/python
cd784148e348: Already exists
a5ca736b15eb: Already exists
f320f547ff02: Pull complete
2edd8ff8cb8f: Pull complete
9381128744b2: Pull complete
Digest: sha256:f708ad35a86f079e860ecdd05e1da7844fd877b58238e7a9a588b2ca3b1534d8
Status: Downloaded newer image for python:3.7-alpine
---> 1a8edcb29ce4
Step 2/12 : ENV PYTHONBUFFERED 1
---> Running in 5178b24df888
Removing intermediate container 5178b24df888
---> 0f928fbf30f1
Step 3/12 : RUN apk add --no-cache postgresql-libs && apk add --no-cache --virtual .build-deps gfortran build-base freetype-dev libpng-dev openblas-dev postgresql-dev python3-dev wget
---> Running in 2a8f4653e3f9
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/5) Installing db (5.3.28-r0)
(2/5) Installing libsasl (2.1.26-r14)
(3/5) Installing libldap (2.4.46-r0)
(4/5) Installing libpq (10.5-r0)
(5/5) Installing postgresql-libs (10.5-r0)
OK: 19 MiB in 39 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/36) Installing binutils (2.30-r5)
(2/36) Installing gmp (6.1.2-r1)
(3/36) Installing isl (0.18-r0)
(4/36) Installing libgomp (6.4.0-r9)
(5/36) Installing libatomic (6.4.0-r9)
(6/36) Installing pkgconf (1.5.3-r0)
(7/36) Installing libgcc (6.4.0-r9)
(8/36) Installing mpfr3 (3.1.5-r1)
(9/36) Installing mpc1 (1.0.3-r1)
(10/36) Installing libstdc++ (6.4.0-r9)
(11/36) Installing gcc (6.4.0-r9)
(12/36) Installing libquadmath (6.4.0-r9)
(13/36) Installing libgfortran (6.4.0-r9)
(14/36) Installing gfortran (6.4.0-r9)
(15/36) Installing libmagic (5.32-r0)
(16/36) Installing file (5.32-r0)
(17/36) Installing musl-dev (1.1.19-r10)
(18/36) Installing libc-dev (0.7.1-r0)
(19/36) Installing g++ (6.4.0-r9)
(20/36) Installing make (4.2.1-r2)
(21/36) Installing fortify-headers (0.9-r0)
(22/36) Installing build-base (0.5-r1)
(23/36) Installing libpng (1.6.34-r1)
(24/36) Installing freetype (2.9.1-r1)
(25/36) Installing zlib-dev (1.2.11-r1)
(26/36) Installing libpng-dev (1.6.34-r1)
(27/36) Installing freetype-dev (2.9.1-r1)
(28/36) Installing openblas-ilp64 (0.3.0-r0)
(29/36) Installing openblas (0.3.0-r0)
(30/36) Installing openblas-dev (0.3.0-r0)
(31/36) Installing libressl-dev (2.7.4-r0)
(32/36) Installing postgresql-dev (10.5-r0)
(33/36) Installing python3 (3.6.6-r0)
(34/36) Installing python3-dev (3.6.6-r0)
(35/36) Installing wget (1.19.5-r0)
(36/36) Installing .build-deps (0)
Executing busybox-1.28.4-r2.trigger
OK: 488 MiB in 75 packages
Removing intermediate container 2a8f4653e3f9
---> 0a6733c0891e
Step 4/12 : WORKDIR /app
---> Running in e99a4dadbd78
Removing intermediate container e99a4dadbd78
---> 11d698c20e86
Step 5/12 : COPY ./misc/requirements.txt /app/
---> aa6b85587b84
Step 6/12 : RUN pip search tensorflow
---> Running in a4434a87e740
tensorflow (1.12.0) - TensorFlow is an open source machine learning framework for everyone.
tensorflow-qndex (0.0.22) - tensorflow-qnd x tensorflow-extenteten
tensorflow-estimator (1.10.12) - TensorFlow Estimator.
mesh-tensorflow (0.0.5) - Mesh TensorFlow
tensorflow-io (0.1.0) - TensorFlow IO
tensorflow-plot (0.2.0) - TensorFlow Plot
tensorflow-lattice (0.9.8) - TensorFlow Lattice provides lattice models in TensorFlow
tensorflow-datasets (0.0.2) - tensorflow/datasets is a library of datasets ready to use with TensorFlow.
tensorflow-extenteten (0.0.22) - TensorFlow extention library
cxflow-tensorflow (0.5.0) - TensorFlow extension for cxflow.
emloop-tensorflow (0.1.0) - TensorFlow extension for emloop.
tensorflow-k8s (0.0.2) - Tensorflow serving extension
tensorflow-transform (0.11.0) - A library for data preprocessing with TensorFlow
dask-tensorflow (0.0.2) - Interactions between Dask and Tensorflow
tensorflow-tracer (1.1.0) - Runtime Tracing Library for TensorFlow
sagemaker-tensorflow (1.12.0.1.0.0.post1) - Amazon Sagemaker specific TensorFlow extensions.
tensorflow-qnd (0.1.11) - Quick and Dirty TensorFlow command framework
tensorflow-probability (0.5.0) - Probabilistic modeling and statistical inference in TensorFlow
tensorflow-utils (0.1.0) - Classes and methods to make using TensorFlow easier
tensorflow-model (0.1.1) - Command-line tool to inspect TensorFlow models
tensorflow-lattice-gpu (0.9.8) - TensorFlow Lattice provides lattice models in TensorFlow
tensorflow-template (0.2) - A tensorflow template for quick starting a deep learning project.
tensorflow-rocm (1.12.0) - TensorFlow is an open source machine learning framework for everyone.
intel-tensorflow (1.12.0) - TensorFlow is an open source machine learning framework for everyone.
tensorflow-font2char2word2sent2doc (0.0.12) - TensorFlow implementation of Hierarchical Attention Networks for Document Classification
tensorflow-gpu (1.12.0) - TensorFlow is an open source machine learning framework for everyone.
tensorflow-aarch64 (1.2) - Tensorflow r1.2 for aarch64[arm64,pine64] CPU only.
tensorflow-fedora28 (1.9.0rc0) - TensorFlow is an open source machine learning framework for everyone.
tensorflow-model-analysis (0.11.0) - A library for analyzing TensorFlow models
tensorflow-transform-canary (0.9.0) - A library for data preprocessing with TensorFlow
rav-tensorflow-transform (0.7.0.910) - A library for data preprocessing with TensorFlow
tensorflow-serving-api (1.12.0) - TensorFlow Serving Python API.
tensorflow-serving-client (0.0.10) - Python client for tensorflow serving
tensorflow-hub (0.2.0) - TensorFlow Hub is a library to foster the publication, discovery, and consumption of reusable parts of machine learning models.
tensorflow-estimator-2.0-preview (1.13.0.dev2019010100) - TensorFlow Estimator.
ngraph-tensorflow-bridge (0.8.0) - Intel nGraph compiler and runtime for TensorFlow
tensorflow-probability-gpu (0.4.0) - Probabilistic modeling and statistical inference in TensorFlow
simple-tensorflow-serving (0.6.6) - The simpler and easy-to-use serving service for TensorFlow models
tensorflow-auto-detect (1.11.0) - Automatically install CPU or GPU tensorflow determined by looking for a CUDA installation.
tensorflow-serving-api-python3 (1.8.0) - *UNOFFICIAL* TensorFlow Serving API libraries for Python3
tensorflow-exercise-hx (1.0.1) - tensorflow练习:鸢尾花种类预测,加州房价预测
tensorflow-metadata (0.9.0) - Library and standards for schema and statistics.
tensorflow-tensorboard (1.5.1) - TensorBoard lets you watch Tensors Flow
resnet-tensorflow (0.0.1) - Deep Residual Neural Network
mlops-tensorflow (0.1.0) -
tensorflow-gpu-macosx (1.8.1) - Unoffcial NVIDIA CUDA GPU support version of Google Tensorflow for MAC OSX 10.13. For more info, please check out my github page. I highly recommend you directly download and install it from my github's release. If you insist on compiling it, you'd do it on a shell to debug.
syntaxnet-with-tensorflow (0.2) - SyntaxNet: Neural Models of Syntax
tensorflow-data-validation (0.11.0) - A library for exploring and validating machine learning data.
ogres (0.0.2) - Thin tensorflow wrapper. Requires tensorflow
tfmesos (0.0.10) - Tensorflow on Mesos
tf-estimator-nightly (1.12.0.dev20181217) - TensorFlow Estimator.
TFBOYS (0.0.1) - TensorFlow BOYS
TFTree (0.1.0) - Tree to tensorflow
tfdebugger (0.1.1) - TensorFlow Debugger
tfextras (0.0.8) - Tensorflow extras
tfu (0.0.1.dev0) - tensorflow utils
tnt (0.12.0.7) - tnt is not tensorflow
easytf (13.9) - Tensorflow CS
tftf (0.0.29) - TensorFlow TransFormer
tf-datasets (0.0.1) - tensorflow/datasets
tfds-nightly (0.0.2.dev201901020014) - tensorflow/datasets is a library of datasets ready to use with TensorFlow.
tf-common (1.0.0) - A common liberary of tensorflow
ParticleFlow (0.0.1) - Particle simulations with tensorflow
tf_decompose (0.1) - Tensor decomposition with TensorFlow
tensorbase (0.3) - Minimalistic TensorFlow Framework
miniflow (0.2.9) - Minimal implementation of TensorFlow
bob.learn.tensorflow (1.0.3) - Bob bindings for tensorflow
quantile-transformer-tf (1.2) - An implementation of QuantileTransformer in tensorflow
tf-env (0.1.0) - RL environments for TensorFlow.
tfseqestimator (2.2.0) - Sequence estimators for Tensorflow
wavenet (0.1.2) - An implementation of WaveNet for TensorFlow.
tf_kaldi_io (0.3.0) - kaldi-io for Tensorflow
ptfutils (0.0.29) - Useful modules for tensorflow
iceflow (0.0.1a2) - tensorflow meta-framework
tf2onnx (0.3.2) - Tensorflow to ONNX converter
tensorforce (0.4.3) - Reinforcement learning for TensorFlow
simnets (0.0.1) - SimNets implementation in tensorflow
saliency (0.0.2) - Saliency methods for TensorFlow
tensor-lib (1.8.19) - Simplified tensorflow library
tensorsets (0.1.0) - Standard datasets for TensorFlow.
tfstage (0.1.7) - TensorFlow project scaffolding
top-hat (0.0.2) - Recommendation system in TensorFlow
TensorMol (0.1) - TensorFlow+Molecules = TensorMol
tfshop (0.0.1) - common tensorflow paradigms
kfac (0.1.0) - K-FAC for TensorFlow
transferflow (0.1.8) - Transfer learning for Tensorflow
train (0.0.3) - Training utilities for TensorFlow.
vibranium (0.1.0) - Opinionated Tensorflow projects
tf-data (0.0.4) - Easy datasets for tensorflow
tensorfunk (0.0.0) - tensorflow model converter to create tensorflow-independent prediction functions.
tf1 (1.1.0) - F1-score metric for TensorFlow
tensorboard-easy (0.2.3) - A tensorflow-independent tensorboard logger
gpflow (1.3.0) - Gaussian process methods in tensorflow
layer (0.1.14) - tensorflow custom comfort wrapper
tflab (0.1.3) - A laboratory for experimenting with Tensorflow abstraction
tensorpack (0.9.0.1) - Neural Network Toolbox on TensorFlow
tensorflowservingclient (0.5.1.post2) - Prebuilt tensorflow serving client
EasyFlow (0.1.dev3) - Modular Distributed TensorFlow Framework
tfgraph (0.2) - Python's Tensorflow Graph Library
serving-utils (0.6.0) - Some utilities for tensorflow serving
Removing intermediate container a4434a87e740
---> a14248285cb2
Step 7/12 : RUN pip install tensorflow
---> Running in 2c14fe29c431
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
ERROR: Service 'app' failed to build: The command '/bin/sh -c pip install tensorflow' returned a non-zero code: 1
Do I have to resort to building tensorflow from source?
EDIT
Writing this question made me realize I could use two separate containers: one for my Django app and a prebuilt tensorflow with gpu. I would still like to learn how to resolve issues like this, but any pointers to docs how to make two separate docker containers talk, would be appreciated.
It looks like tensorflow only publishes wheels (and only up to 3.6), and Alpine linux is not manylinux1-compatible due to its use of musl instead of glibc. Because of this, pip cannot find a suitable installation candidate and fails. Your best options are probably to build from source or change your base image.
Depending on what you're doing, consider if you need alpine at all. If you're like me and only using apk add to install things that allow you to install certain Python packages, you might be fine if you remove all your apk add commands and replace FROM python:3.6-alpine with FROM python:3.6. Tensorflow installs without any issue from that build.
Edit: Never mind, FROM python:3.6 simply installs Ubuntu anyway. If you're looking for a smaller image without some of the drawbacks of Alpine, consider using FROM python:3.7-slim-buster instead.
Related
I can't get the GPU to work even though i chose the GPU option with 4 hours at the start. Is there something to do in order to activate it?
edit:
I installed pytorch with cuda:
%conda install pytorch torchvision torchaudio cudatoolkit=11.4 -c pytorch
Could you try building a custom environment via the YAML file option, using something like this (below is just an example file that works for me, you can add remove packages specific to your use case)
name: torch
channels:
- pytorch
dependencies:
- python=3.9
- pip
- pip:
- ipywidgets
- conda
- conda:
- ipykernel
- pytorch
- torchvision
- torchaudio
- torchserve
- cudatoolkit=11.3
- sklearn
my caffe is installed by the cmd:
conda install caffe-gpu
but how should I train my model with this pkg? In official docs( or some github repos), we will compile it and run it with
/home/xxx/caffe/distribute/bin/caffe.bin train --gpu 4 xxx
and when I used pytorch, I can also install with conda and using the module
python -m torch.distributed.lanch xxx.py
,but I cannot find this way in caffe, thx~
The anaconda caffe package provides the binary caffe, which sits in your anaconda folder under bin and you should be able to just run it if you type in your command line:
caffe train --gpu 4 xxx
I am using an existing model to train a CRNN model which is based on Tensorflow and Keras. I am using anaconda-navigator to train the model.
When the model is being trained, it does not seem to use GPU as my GPU usage is at 5-6%.
I am attaching images of top -i command, Nvidia Xserver, and also my gpu is not being picked up by Tensorflow as tf.test.gpu_device_name() only shows CPU as shown in the below screenshot tf.test.gpu_device_name()
Tensorflow and Keras Versions in anaconda
top -i output
After looking at your TensorFlow and Keras versions in anaconda, i found there is a tensorflow-gpu package missing. It looks like you have only installed TensorFlow CPU version and not the GPU version. If you had installed the GPU version of TensorFlow, then the anaconda navigator would also show a metapackage of TensorFlow GPU library.
That is the reason why you don't see the details of your GPU with the command tf.test.gpu_device_name()
TensorFlow GPU will automatically load the CUDA libraries corresponding to your GPU.
Since you are using anaconda environment install the GPU version as follows
Activate your conda environment
conda install -c anaconda tensorflow-gpu
This command would install TensorFlow v2.2.0 to your conda environment.
If you want the latest tf v2.4 then try using pip to install the specific version inside your conda environment
pip install tensorflow-gpu==2.4
Keras will automatically be installed with TensorFlow 2.0 verison. You can use Keras library with TensorFlow backend. If you want a specific version of Keras, you can always install it using pip
As the title clearly describes the situation I'm facing, I'm getting the following warning on Google Colab while using the Theano as the backend of Keras:
WARNING (theano.tensor.blas): We did not find a dynamic library in the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library.
So, how can I provide the the dynamic library used for blas for Theano on Google Colab?
p.s. I've already installed the Theano package. The libgpuarray, and pygpu packages according to the official documentation.
Software Stack:
Keras version: 2.3.1.
Python version: 3.6.9.
Theano version: 1.0.4.
could you try this?
!wget -c https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
!chmod +x Anaconda3-5.1.0-Linux-x86_64.sh
!bash ./Anaconda3-5.1.0-Linux-x86_64.sh -b -f -p /usr/local
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages/')
#install theano and pygpu
!conda install theano pygpu
It downloads a host of dependencies which are used for theano.
I have built a random forest model on VM. It has python 3.5.3, sklearn 0.0 and scikit-learn 0.22.2.post1. I am building a docker with python 3.6 Docker and installing the exact versions and packages as present on VM (Note: did pip freeze to requirement.txt and using that to install requirements on docker).
The error found when docker logs are checked after build is as follows:
**ModuleNotFoundError: No module named 'sklearn.ensemble._forest'**.
I also tried building the same module with python 3.7 but i am not able to install python 3.5 or 3.7 on docker. The models are being stored as joblib files.
Use scikit-learn==0.20.4 package, it worked for me with python-3.7. The latest version 0.23.1 gives you 'sklearn.ensemble._forest' error.