Tag:pytorch

  • Pytorch’s gradient calculation and detailed explanation of backward method

    Time:2021-4-12

    Basic knowledge tensors: Tensor is an n-dimensional array in Python. We can specify the parameter reuqires_ Grad = true to create a back propagation graph so that the gradient can be calculated. In Python, it is generally called dynamic computation graph (DCG), that is, dynamic computation graph. import torch import numpy as np #Mode one […]

  • Solve the problem of Python error: assertionerror: invalid device ID

    Time:2021-4-8

    The network trained on the server is sent to the local desktop computer for infer. As a result, an error is reported AssertionError: Invalid device id After careful inspection, it is found that there are multiple GPUs in the original server, and two GPUs were turned on at that time for acceleration. net1 = nn.DataParallel(net1, […]

  • Pytorch Gan generates counter network instance

    Time:2021-4-7

    I don’t want to talk much nonsense. Let’s go straight to the code! import torch import torch.nn as nn from torch.autograd import Variable import numpy as np import matplotlib.pyplot as plt torch.manual_seed(1) np.random.seed(1) BATCH_SIZE = 64 LR_G = 0.0001 LR_D = 0.0001 N_IDEAS = 5 ART_COMPONENTS = 15 PAINT_POINTS = np.vstack([np.linspace(-1,1,ART_COMPONENTS) for _ in range(BATCH_SIZE)]) […]

  • Pytorch: a simple Gan example (MNIST dataset)

    Time:2021-4-6

    I don’t want to talk much nonsense. Let’s go straight to the code! # -*- coding: utf-8 -*- “”” Created on Sat Oct 13 10:22:45 2018 @author: www “”” import torch from torch import nn from torch.autograd import Variable import torchvision.transforms as tfs from torch.utils.data import DataLoader, sampler from torchvision.datasets import MNIST import numpy as […]

  • How to forge handwritten MNIST dataset in Python Gan

    Time:2021-4-3

    1、 MNIST dataset The MNIST data set is the handwritten numeral in the figure above. 2、 Gan principle (generation countermeasure network) Gan network consists of two parts: one is generator (g), the other is discriminator (d) At the beginning, G is composed of noises that obey certain distributions (such as Gaussian distribution). The generated images […]

  • How Python prepares, trains and tests its own image data

    Time:2021-4-2

    Most of the introductory tutorials of Python use the data in torch vision for training and testing. If we are our own image data, what should we do? 1、 My data When I study, I use fashion MNIST. This data is relatively small. My computer does not have a GPU, so I can still afford […]

  • How to implement MNIST classification with Python

    Time:2021-4-1

    The torch vision package contains the current popular data sets, model structure and commonly used image conversion tools. torchvision.datasets The following data sets are included in MNISTCoco (captioning and detection) LSUN Classification ImageFolder Imagenet-12 CIFAR10 and CIFAR100 STL10 torchvision.models torchvision.models The sub modules of the module contain the following model structures. AlexNet VGG ResNet SqueezeNet […]

  • Python uses MNIST data set to implement cgan and generate specified digital mode

    Time:2021-3-31

    Cgan is conditional generative adverse networks, which can generate countermeasure network conditionally. Based on the initial Gan, the corresponding information of the picture is added. Cgan is implemented by traditional convolution. import torch from torch.utils.data import DataLoader from torchvision.datasets import MNIST from torchvision import transforms from torch import optim import torch.nn as nn import matplotlib.pyplot […]

  • Python uses MNIST data set to realize the detailed explanation of basic Gan and dcgan

    Time:2021-3-30

    Generative adverse networks Gan includes generator and discriminator. The data includes real data, groundtruth, and “fake” data generated by network. The purpose is that the fake data generated by network can “cheat” the discriminator, so that the discriminator can’t recognize it. That is to say, the discriminator can’t distinguish the real data from fake data. […]

  • Detailed explanation on preprocessing of MNIST dataset of Python

    Time:2021-3-25

    Detailed explanation on preprocessing of MNIST dataset of Python The accuracy of MNIST is 99.7% The implementation of convolutional neural network (CNN) for MNIST has various technologies, such as data enhancement, loss, pseudo randomization, etc. Operating system: Ubuntu 18.04 Graphics card: gtx1080ti Python version: 2.7 (3.7) Network architecture CNN with four layers has the following […]

  • An example of MNIST handwritten numeral recognition and classification by using LSTM in Python

    Time:2021-3-21

    The code is as follows. I think the most important thing for beginners is to learn the format of RNN reading data. # -*- coding: utf-8 -*- “”” Created on Tue Oct 9 08:53:25 2018 @author: www “”” import sys sys.path.append(‘..’) import torch import datetime from torch.autograd import Variable from torch import nn from torch.utils.data […]

  • How to freeze a layer’s parameters in Python

    Time:2021-3-17

    When we transfer to finetune, we usually need to freeze the parameters of the previous layers and not participate in training. The implementation in Python is as follows: class Model(nn.Module): def __init__(self): super(Transfer_model, self).__init__() self.linear1 = nn.Linear(20, 50) self.linear2 = nn.Linear(50, 20) self.linear3 = nn.Linear(20, 2) def forward(self, x): pass If we want to freeze […]