<jupyter_start><jupyter_text><jupyter_code>import torch
import torch.nn as nn
import torchvision
import numpy as np
import torch.optim as optim
import matplotlib.pyplot as plt
import time
!git clone https://github.com/Shakil-1501/TSAI.git
from TSAI.S11 import CustomResNet
use_cuda = torch.cuda.is_available()
device = torch.device("cuda" if use_cuda else "cpu")
print("Device : ",device)
model = CustomResNet.CustomResNet().to(device)
print("Model Loaded Successfully ")
from TSAI.S11 import albumentationstransform
albumentationstransform_train_transforms = albumentationstransform.train_transforms()
from TSAI.S11 import dataloader
trainloader , testloader = dataloader.datasetloader(albumentationstransform_train_transforms , batchsize = 512 , numwork = 4 )
classes = ('plane', 'car', 'bird', 'cat','deer', 'dog', 'frog', 'horse', 'ship', 'truck')
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(model.parameters(), lr = 0.00001 , momentum = 0.9 )
from TSAI.S11 import LRScheduler
lrfinder = LRScheduler.LRFinder(model, optimizer , criterion , device = "cuda")
lrfinder.range_test(trainloader , end_lr =  0.1 , num_iter = 100 , step_mode = "linear" )
lrfinder.plot()
lrfinder.reset()
from TSAI.S11 import traindataset
print("Devive : ", device)
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(model.parameters(), lr = 0.003 , momentum = 0.95 , weight_decay = 0.01 )
scheduler = torch.optim.lr_scheduler.OneCycleLR( optimizer , max_lr = 0.01 , div_factor = 10 , pct_start  = 5/24 ,
                                                 cycle_momentum = True , epochs = 24 , steps_per_epoch = len(trainloader),
                                                 final_div_factor = 1 , anneal_strategy = 'linear' )

start_time = time.time()
traindataset.traindataset(range_ = 24 , model = model , device = device , 
                          trainloader = trainloader , optimizer = optimizer  , criterion_ = criterion ,
                          batchsize = 512 , scheduler_ = scheduler )
end_time = time.time()
print("Training Time : ",end_time-start_time)
from TSAI.S11 import testdataset
testdataset.testdataset(model = model , device = device , testloader = testloader )<jupyter_output>/content/TSAI/S11/CustomResNet.py:57: UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.
  return F.log_softmax(x)
StarcoderdataJupyterStructuredCleanDedup