<jupyter_start><jupyter_text>Modelling<jupyter_code>import torch.nn as nn
import torch.nn.functional as F
class BaseLine(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(3,32,5)
        self.conv2 = nn.Conv2d(32,64,5)
        self.conv2batchnorm = nn.BatchNorm2d(64)
        self.conv3 = nn.Conv2d(64,128,5)
        self.fc1 = nn.Linear(128*10*10,256)
        self.fc2 = nn.Linear(256,128)
        self.fc3 = nn.Linear(128,50)
        self.relu = nn.ReLU()
    
    def forward(self,X):
        preds = F.max_pool2d(self.relu(self.conv1(X)),(2,2))
        preds = F.max_pool2d(self.relu(self.conv2batchnorm(self.conv2(preds))),(2,2))
        preds = F.max_pool2d(self.relu(self.conv3(preds)),(2,2))
        preds = preds.view(-1,128*10*10)
        preds = self.relu(self.fc1(preds))
        preds = self.relu(self.fc2(preds))
        preds = self.relu(self.fc3(preds))
        return preds
device = torch.device('cuda')
from torchvision import models
# model = BaseLine().to(device)
# model = model.to(device)

model = models.resnet18(pretrained=True).to(device)
in_f = model.fc.in_features
model.fc = nn.Linear(in_f,50)
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(model.parameters(),lr=0.1)
PROJECT_NAME = 'Car-Brands-Images-Clf'
import wandb
EPOCHS = 100
BATCH_SIZE = 32
from tqdm import tqdm
wandb.init(project=PROJECT_NAME,name='transfer-learning')
for _ in tqdm(range(EPOCHS)):
    for i in range(0,len(X_train),BATCH_SIZE):
        X_batch = X_train[i:i+BATCH_SIZE].view(-1,3,112,112).to(device)
        y_batch = y_train[i:i+BATCH_SIZE].to(device)
        preds = model(X_batch)
        preds = preds.to(device)
        loss = criterion(preds,y_batch)
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
        wandb.log({'loss':loss.item()})
for index in range(len(preds)):
    print(torch.argmax(torch.round(preds)[index]))
    print(y_batch[index])
    print('\n')<jupyter_output>tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, device='cuda:0')
tensor(37, device='cuda:0')


tensor(16, dev[...]
{'fraction_non_alphanumeric': 0.1855324849296718, 'fraction_numerical': 0.06597454789015406, 'mean_word_length': 4.362657091561939, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '121203', 'license': 'Apache-2.0', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1223, 'n_words': 177, 'path': 'wandb/run-20210522_002051-1p84yzlz/tmp/code/00-main.ipynb', 'repo_name': 'Programmer-RD-AI/Car-Brands-Images-Clf-100th-Project', 'size': '2986'}