I will give you a code , you have to change one structure .... in the code there was…
- User
I will give you a code , you have to change one structure .... in the code there was written vgg16 , you have use lstm insteed of vgg16 and all others things will be same here is the code - " here is the code modify it - "#!/usr/bin/env python3
-- coding: utf-8 --
""" Created on Mon Mar 16 15:16:08 2020
@author: kalpita """
#matplotlib inline import torch import numpy as np import torch.nn as nn import torch.nn.functional as F import matplotlib.pyplot as plt from torchvision import transforms, datasets import torchvision.datasets as datasets import torchvision.models as models
import os
My_dir = os.listdir('/media/nibaran/New Volume/Jaya/deep_learning_LineData') print(My_dir) print(len(My_dir)) num_epochs = len(My_dir) for epoch in range(num_epochs): print(My_dir[epoch]) Ptrain = os.path.join('/media/nibaran/New Volume/Jaya/deep_learning_LineData' + '/' + My_dir[epoch] + '/' + 'train'+ '/') print(Ptrain)
PATH = os.path.join('/media/nibaran/New Volume/Jaya/line_result/Train_WTTest' + My_dir[epoch] +'.pth' )
Ptest = os.path.join('/media/nibaran/New Volume/Jaya/deep_learning_LineData' + '/' + My_dir[epoch] + '/' + 'test' + '/') print(Ptest)
PATH1 = os.path.join('/media/nibaran/New Volume/Jaya/line_result/ModelTest' + My_dir[epoch] +'.pth' )
Load data
apply_transform = transforms.Compose([transforms.RandomResizedCrop(224),transforms.RandomHorizontalFlip(), transforms.ToTensor()]) BatchSize = 1 # change according to system specs
#trainset = datasets.MNIST(root='./MNIST', train=True, download=True, transform=apply_transform) #train_path='/media/nibaran/New Volume/Jaya/nEW_rUN/bangla_data_deep/86/train/' trainset=datasets.ImageFolder(Ptrain, transform=apply_transform) trainLoader = torch.utils.data.DataLoader(trainset, batch_size=BatchSize, shuffle=True, num_workers=1) # Creating dataloader
Validation set with random rotations in the range [-90,90]
#testset = datasets.MNIST(root='./MNIST', train=False, download=True, transform=apply_transform) #test_path='/media/nibaran/New Volume/Jaya/nEW_rUN/bangla_data_deep/86/test/' testset=datasets.ImageFolder(Ptest, transform=apply_transform) testLoader = torch.utils.data.DataLoader(testset, batch_size=BatchSize, shuffle=False, num_workers=1) # Creating dataloader
Size of train and test datasets
print('No. of samples in train set: '+str(len(trainLoader.dataset))) print('No. of samples in test set: '+str(len(testLoader.dataset))) Notrain = len(trainLoader.dataset) Notest = len(testLoader.dataset) #Define model architecture
use_gpu = torch.cuda.is_available() net = models.vgg16(pretrained=True) net.classifier._modules['6'] = nn.Linear(4096, 2) print(net) if use_gpu: print('GPU is avaialble!') net = net.cuda()
train model
criterion = nn.CrossEntropyLoss() learning_rate = 0.0001 num_epochs = 100
- Assistant