コード例 #1
0
ファイル: convolutions.py プロジェクト: mingxiaoh/pytorch
    def test_conv2d_ext(self, device, dtype):
        # this list for save the cases which dh,dw == 0
        # and raise error in the end
        self.Fail = list()

        total_cases = self._collect_cases()
        for case in total_cases:
            case_name = case['case_name']
            bs = case['mb']
            group = case['g']
            ic, ih, iw = case['ic'], case['ih'], case['iw']
            oc = case['oc']
            kh, kw = case['kh'], case['kw']
            sh, sw = case['sh'], case['sw']
            ph, pw = case['ph'], case['pw']
            dh, dw = case['dh'], case['dw']
            has_bias = case['bias']
            if dh == 0 or dw == 0:
                self.Fail.append(case_name)
                continue

            ic_g = ic // group
            torch.manual_seed(1)
            input = torch.randn((bs, ic, ih, iw),
                                device=device,
                                dtype=dtype,
                                requires_grad=True)
            weight = torch.randn(
                (oc, ic_g, kh, kw), device=device, dtype=dtype) * 0.01
            bias = None if has_bias == 'False' else torch.randn(
                (oc), device=device, dtype=dtype)

            k = [kh, kw]
            s = [sh, sw]
            p = [ph, pw]
            d = [dh, dw]
            thnn_output = self._thnn_conv_group(input, weight, k, bias, s, p,
                                                d, group)
            if self.device_type == 'cpu' and torch.backends.mkldnn.is_available(
            ):
                output = torch.mkldnn_convolution(input, weight, bias, p, s, d,
                                                  group)
            elif self.device_type == 'cuda' and torch.backends.cudnn.is_available(
            ):
                output = torch.cudnn_convolution(input, weight, bias, p, s, d,
                                                 group, True, True)
            else:
                output = torch.conv2d(input, weight, bias, s, p, d, group)

            msg = 'device:{}, dtype:{}, group:{}, batchsize:{}' \
                  'input channel:{}, output channel:{}, ' \
                  'bias:{}, padding:{}, dilation:{}, stride:{}, ' \
                  'kernel:{}'
            msg = msg.format(device, dtype, group, bs, ic, oc, has_bias, p, d,
                             s, k)

            if self.device_type == 'cuda' and cudnn.is_available():
                self.assertEqual(output,
                                 thnn_output,
                                 msg=msg,
                                 atol=1e-2,
                                 rtol=1e-2)
            else:
                self.assertEqual(output, thnn_output, msg=msg)

        if self.Fail != []:
            warnings.warn('invalid cases dilation height or weight is 0: ' +
                          ",".join(self.Fail))
コード例 #2
0
ファイル: gpu_avaliable.py プロジェクト: Cyan95/Deep-Packet
# 判断是否安装了cuda
import torch
print(torch.__version__)

import torch
x = torch.rand(5, 3)
print(x)

print(torch.cuda.is_available())  #返回True则说明已经安装了cuda

# 判断是否安装了cuDNN
from torch.backends import cudnn
print(cudnn.is_available())  #返回True则说明已经安装了cuDNN
コード例 #3
0
from hippo7_app.hippo7_backend.opengl.render import WindowManager
from hippo7_app.hippo7_backend.server import start_server

model_type = "biggan-deep-512"
fullscreen = False


def get_device():
    return "cuda:0" if is_available() else "cpu"


if get_device().startswith("cuda"):  # This optimizes performance in cuda mode
    print("CUDA enabled, using GPU!")
    from torch.backends import cudnn  # QA

    if cudnn.is_available():
        cudnn.enabled = True
        cudnn.benchmark = True

# create window with OpenGL context
app.use("pyglet")
window = app.Window(512, 512, fullscreen=False, decoration=True)
WindowManager.bind_window(window)

# Instantiate generator
# generator = simple_gan_setup(model_type=model_type)
# generator = no_gan_setup()
generator = complex_gan_setup(model_type=model_type)

# visualize_graph(generator)
コード例 #4
0
ファイル: 1-test.py プロジェクト: Shijie97/PytorchPrograming
# !user/bin/python
# -*- coding: UTF-8 -*-

import torch
from torch.backends import cudnn
import torch.nn.functional as F

a = torch.tensor(1.)
# 若正常则静默

print(a.cuda())
# 若正常则返回 tensor(1., device='cuda:0')

print(cudnn.is_available())
# 若正常则返回 True

print(cudnn.is_acceptable(a.cuda()))
# 若正常则返回 True

print(torch.__version__)  # 1.2.0

print(torch.cuda.is_available())  # True

x = torch.Tensor([4.0] * 4).view(1, 4)
print(F.softmax(x, dim=1))  # tensor([[0.2500, 0.2500, 0.2500, 0.2500]])

print(torch.cuda.device_count())  # 1

print(torch.cuda.get_device_name(0))  # GeForce GTX 960M

print(torch.cuda.current_device())  # 0
コード例 #5
0
lr = 0.0002

# Beta1 hyperparam for Adam optimizers
beta1 = 0.5

# Number of GPUs available. Use 0 for CPU mode.
ngpu = 1

# If we want to train or test the model
train = True

# If we need to download the dataset
download = False

device = torch.device("cuda:0" if (
    cudnn.is_available() and ngpu > 0) else "cpu")


# Values come from paper
def weights_init(m):
    classname = m.__class__.__name__
    if classname.find('Conv') != -1:
        nn.init.normal_(m.weight.data, 0.0, 0.02)
    elif classname.find('BatchNorm') != -1:
        nn.init.normal_(m.weight.data, 1.0, 0.02)
        nn.init.constant_(m.bias.data, 0)


def smooth_positive_labels(y):
    return y - 0.3 + (torch.rand(y.shape) * 0.5).to(device)
コード例 #6
0
ファイル: 7_mnist.py プロジェクト: Mute-xD/DeepLearn
 def __init__(self):
     self.writer = self.setWriter()
     self.batchSize = 64
     self.trainSetSize, self.testSetSize = None, None
     cudnn.benchmark = True
     print(cudnn.is_available())
コード例 #7
0
ファイル: cudnn.py プロジェクト: SunDoge/flame
def cudnn_benchmark_if_possible():
    if torch.cuda.is_available() and cudnn.is_available():
        cudnn.benchmark = True
        _logger.info('cudnn.benchmark=%s', cudnn.benchmark)
    else:
        _logger.warning('cudnn is not available')