Advertisement
Guest User

fastai inprog docker

a guest
Dec 6th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. FROM nvidia/cuda:10.2-base
  2.  
  3. RUN apt-get update && \
  4. apt-get install -y --no-install-recommends git
  5.  
  6. SHELL ["/bin/bash", "-c"]
  7.  
  8. #setup miniconda
  9. ENV CONDAROOT "/opt/conda"
  10.  
  11. WORKDIR /root/
  12. ADD https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh /root/
  13.  
  14. RUN mkdir ~/.conda && \
  15. bash Miniconda3-latest-Linux-x86_64.sh -b -p $CONDAROOT && \
  16. #rm -rf Miniconda3-latest-Linux-x86_64.sh && \
  17. ln -s $CONDAROOT/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
  18. source $CONDAROOT/etc/profile.d/conda.sh
  19.  
  20. # add conda to path
  21. ENV PATH $CONDAROOT/bin:$PATH
  22.  
  23. # install conda packages, -c are channels for dependencies, -n are virtual env
  24. RUN conda update -n base -c defaults conda && \
  25. conda create -n torch -y python=3.7 && \
  26. conda install -n torch pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch && \
  27. conda install -n torch -c fastai -c pytorch fastai && \
  28. conda install -n torch -c conda-forge imageio matplotlib seaborn pandas jupyter jupyterlab scikit-image scikit-learn tqdm jupyter_contrib_nbextensions tensorboard grpcio && \
  29. conda install -n torch -c conda-forge nodejs=10.13
  30.  
  31. # see about adding optimized pillow at some later time
  32.  
  33. # activate torch environment to install packages that are outdated or not available through conda
  34. ENV PATH $CONDAROOT/envs/torch/bin:$PATH
  35. RUN echo "source activate torch" >> ~/.bashrc && \
  36. source activate torch && \
  37. pip install opencv-python albumentations pretrainedmodels efficientnet-pytorch torchsummary future absl-py jupyter-tensorboard hiddenlayer && \
  38. pip install --no-dependencies git+https://github.com/qubvel/segmentation_models.pytorch
  39.  
  40. #configure jupyter-lab to run in the docker image as root with bash as terminal and no password
  41. # notebook directory is /opt/notebooks ==> this should be your mount point
  42. RUN jupyter-lab --generate-config
  43.  
  44. RUN sed -i '/c.NotebookApp.notebook_dir/c\c.NotebookApp.notebook_dir = "'"/opt/notebooks"'"' ~/.jupyter/jupyter_notebook_config.py && \
  45. sed -i '/c.NotebookApp.open_browser/c\c.NotebookApp.open_browser = False' ~/.jupyter/jupyter_notebook_config.py && \
  46. sed -i '/c.NotebookApp.quit_button/c\c.NotebookApp.quit_button = True' ~/.jupyter/jupyter_notebook_config.py && \
  47. sed -i '/c.NotebookApp.token/c\c.NotebookApp.token = "'""'"' ~/.jupyter/jupyter_notebook_config.py && \
  48. sed -i '/c.NotebookApp.ip/c\c.NotebookApp.ip = "'"0.0.0.0"'"' ~/.jupyter/jupyter_notebook_config.py && \
  49. sed -i '/c.NotebookApp.terminado_settings/c\c.NotebookApp.terminado_settings = {"'"shell_command"'":["'"bash"'"]}' ~/.jupyter/jupyter_notebook_config.py && \
  50. sed -i '/c.NotebookApp.allow_root/c\c.NotebookApp.allow_root = True' ~/.jupyter/jupyter_notebook_config.py && \
  51. jupyter labextension install @jupyter-widgets/jupyterlab-manager && \
  52. jupyter labextension install jupyterlab_tensorboard && \
  53. mkdir /opt/notebooks
  54. WORKDIR /opt/notebooks
  55.  
  56. # Set the random seed and copy the utility scripts to the image
  57. ENV RANDOM_SEED 2019
  58. COPY torchtest.py seed.py /opt/scripts/
  59.  
  60. # this script runs seed.py whenever an ipython kernel/console is started
  61. # this actually creates a dir in /opt/notebooks/'~'/.ipython
  62. # todo: fix this correctly
  63. COPY ipython_config.py ~/.ipython/profile_default/
  64.  
  65. RUN mkdir /opt/cache && \
  66. pip freeze > ~/requirements.txt && \
  67. conda list -n torch --export --json > ~/requirements.json
  68. ENV TORCH_HOME ~/cache/torch
  69. ENV FASTAI_HOME ~/cache/fastai
  70. ENV HOME /root/
  71.  
  72. RUN conda install -c fastai -c pytorch fastbook
  73.  
  74. # Make port 8888 available to the world outside this container
  75. # Expose isn't working properly us -p 8888:8888 instead with docker run
  76. #EXPOSE 8888
  77.  
  78. # Run the torchtest script when the container launches (and no other command is given)
  79. #CMD ["ipython", "/opt/scripts/torchtest.py"]
  80. CMD ["/bin/bash", "-c", "jupyter lab"]
  81.  
  82. #Example Start Image
  83. # docker run --rm -p 8888:8888 -v /temp/persist:/opt/notebooks --runtime=nvidia <image>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement