PyTorch快速开始-Notebook with JupyterHub on K8s

在Kubernetes上的JupyterHub,通过Notebook快速运行PyTorch例程,测试镜像是否可用。

1、快速安装

在我的镜像中,已经将PyTorch、TorchVision打包到JupyterHub for K8s的Notebook镜像中,可以直接使用。

或者,在notebook中进行安装,如下:

%%bash
pip install torch torchvision

2、导入引用库

from __future__ import print_function, division
import os
import torch

3、运行例程

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]])

4、查看torchvision库方法

查看torchvison的信息:

import torchvision
help(torchvision)

输出信息:

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

5、查看torch库方法

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

......

 

更多参考:

转载于:https://my.oschina.net/u/2306127/blog/3071616

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值