Tag:pytorch

  • Pytorch implementation of DPN network

    Time:2021-1-7

    I don’t want to talk much nonsense. Let’s go straight to the code! import torch import torch.nn as nn import torch.nn.functional as F class CatBnAct(nn.Module): def __init__(self, in_chs, activation_fn=nn.ReLU(inplace=True)): super(CatBnAct, self).__init__() self.bn = nn.BatchNorm2d(in_chs, eps=0.001) self.act = activation_fn def forward(self, x): x = torch.cat(x, dim=1) if isinstance(x, tuple) else x return self.act(self.bn(x)) class BnActConv2d(nn.Module): def […]

  • On the implementation of resnext network in Python

    Time:2021-1-4

    PIP install preconditioned models is required here “”” Finetuning Torchvision Models “”” from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.optim as optim import numpy as np import torchvision from torchvision import datasets, models, transforms import matplotlib.pyplot as plt import time import os import copy import argparse import […]

  • Pytorch implementation examples of resnet50, resnet101 and resnet152

    Time:2021-1-2

    PyTorch: https://github.com/shanglianlm0525/PyTorch-Networks import torch import torch.nn as nn import torchvision import numpy as np print(“PyTorch Version: “,torch.__version__) print(“Torchvision Version: “,torchvision.__version__) __all__ = [‘ResNet50’, ‘ResNet101′,’ResNet152’] def Conv1(in_planes, places, stride=2): return nn.Sequential( nn.Conv2d(in_channels=in_planes,out_channels=places,kernel_size=7,stride=stride,padding=3, bias=False), nn.BatchNorm2d(places), nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=3, stride=2, padding=1) ) class Bottleneck(nn.Module): def __init__(self,in_places,places, stride=1,downsampling=False, expansion = 4): super(Bottleneck,self).__init__() self.expansion = expansion self.downsampling = downsampling self.bottleneck = […]

  • Solving pytorch dataloader num_ Problems with workers

    Time:2021-1-1

    Recently, I was learning python. When using data batch training, I used dataloader in parameter num to import data_ The settings of workers make the program run without any response. Take a look at the code Import torch # import module import torch.utils.data as Data BATCH_ Size = 8? Data volume of each batch X= […]

  • Python sets random number seed mode of shuffle in dataloader class

    Time:2020-12-30

    For example: Python sets random number seed mode of shuffle in dataloader class Although there is little difference in the experimental results, there is sometimes a big difference of two percentage points Want to reproduce the results It is found that the random number is used in the shuffle attribute encapsulated in the dataloader class […]

  • Image visualization and storage of MNIST data set by Python

    Time:2020-12-29

    How to visualize and save the image of MNIST data set in Python Export some libraries import torch import torchvision import torch.utils.data as Data import scipy.misc import os import matplotlib.pyplot as plt BATCH_SIZE = 50 DOWNLOAD_MNIST = True Data set preparation #Preparation of training set and test set train_data = torchvision.datasets.MNIST(root=’./mnist/’, train=True,transform=torchvision.transforms.ToTensor(), download=DOWNLOAD_MNIST, ) test_data […]

  • An example of poetry writing based on LSTM neural network under Python

    Time:2020-12-25

    Using tens of thousands of Tang poems as materials, the double-layer LSTM neural network is trained to write poems in the way of Tang poems. The code structure is divided into four parts One model.py The double layer LSTM model is defined Two data.py It defines the processing method of Tang poetry data from the […]

  • Using Python to classify cifar-10 data sets

    Time:2020-12-24

    The steps are as follows: 1. Using torch vision to load and preprocess cifar-10 data set 2. Define the network 3. Define loss function and optimizer 4. Train the network and update the network parameters 5. Test the network Operating environment: windows+python3.6.3+pycharm+pytorch0.3.0 import torchvision as tv import torchvision.transforms as transforms import torch as t from […]

  • Regression curve prediction method based on Python RNN

    Time:2020-12-23

    task Through the input sin curve and the predicted cos curve #Initial load package and define parameters import torch from torch import nn import numpy as np import matplotlib.pyplot as plt torch.manual_ Seed (1) ා #Super parameter setting TIME_SETP=10 INPUT_SIZE=1 LR=0.02 DOWNLoad_MNIST=True Define RNN network structure from torch.autograd import Variable class RNN(nn.Module): def __init__(self): #In […]

  • Examples of implementing LSTM and Gru with Python

    Time:2020-12-21

    In order to solve the problem that traditional RNN can’t rely on long time, two variants of RNN, LSTM and Gru, are introduced. LSTM Long short term memory, called long short term memory network, means long short-term memory, which still solves the problem of short-term memory. This kind of short-term memory is relatively long and […]

  • Example of POS implemented by Python + LSTM

    Time:2020-12-19

    After learning for a few days, I finally understood how to use python This is the code of the official document for direct handling After that, they will try to implement other NLP tasks by themselves # Author: Robert Guthrie import torch import torch.autograd as autograd import torch.nn as nn import torch.nn.functional as F import […]

  • Explanation of LSTM parameter using based on Python

    Time:2020-12-14

    lstm(*input, **kwargs) The multi-layer long short time memory (LSTM) neural network is applied to the input sequence. Parameters: input_ Size: enter the number of expected features in ‘x’ hidden_ Size: number of properties in hidden state ‘H’ num_ Layers: the number of loop layers. For example, set ‘num’_ Layers = 2 ‘means that two lstms […]