在Kubernetes上的JupyterHub,經過Notebook快速運行PyTorch例程,測試鏡像是否可用。python
在個人鏡像中,已經將PyTorch、TorchVision打包到JupyterHub for K8s的Notebook鏡像中,能夠直接使用。git
或者,在notebook中進行安裝,以下:github
%%bash pip install torch torchvision
注意:%%bash爲Notebook的魔法操做符,詳細使用參見:bash
在Github的Databook項目獲取本Notebook的源文件:ide
from __future__ import print_function, division import os import torch
x = torch.rand(5, 3) print(x) 輸出: tensor([[0.4482, 0.9189, 0.2227], [0.3906, 0.4695, 0.1300], [0.5034, 0.7224, 0.0471], [0.5570, 0.4676, 0.8005], [0.0363, 0.2650, 0.1269]])
查看torchvison的信息:測試
import torchvision help(torchvision)
輸出信息:spa
Help on package torchvision: NAME torchvision PACKAGE CONTENTS _C datasets (package) models (package) ops (package) transforms (package) utils version FUNCTIONS get_image_backend() Gets the name of the package used to load images set_image_backend(backend) Specifies the package used to load images. Args: backend (string): Name of the image backend. one of {'PIL', 'accimage'}. The :mod:`accimage` package uses the Intel IPP library. It is generally faster than PIL, but does not support as many operations. VERSION 0.3.0 FILE /opt/conda/lib/python3.6/site-packages/torchvision/__init__.py
help(torch)
輸出信息:
Help on package torch: NAME torch DESCRIPTION The torch package contains data structures for multi-dimensional tensors and mathematical operations over these are defined. Additionally, it provides many utilities for efficient serializing of Tensors and arbitrary types, and other useful utilities. It has a CUDA counterpart, that enables you to run your tensor computations on an NVIDIA GPU with compute capability >= 3.0. PACKAGE CONTENTS _C __config__ _dl _jit_internal _ops _six _storage_docs _tensor_docs _tensor_str _thnn (package) _torch_docs _utils _utils_internal autograd (package) backends (package) contrib (package) cuda (package) distributed (package) distributions (package) for_onnx (package) functional hub jit (package) multiprocessing (package) nn (package) onnx (package) optim (package) quasirandom random serialization sparse (package) storage tensor testing (package) utils (package) version SUBMODULES cpp ops ......