#hey, I am currently trying to make an ai that is trained on official Google Street view images

11 messages · Page 1 of 1 (latest)

jaunty sedge
#

I need helping figuring out how to get training data, and which AI model to use (and maybe help setting it up). I am somewhat new to programming.

This AI I want to be able to play the game "geoguessr" and very accurately pinpoint the location based on vegetation, camera quality, ect.

Some other people have made ais for this but they didn't really document any of it. They used tinyViT

Any help would be appreciated

jaunty sedge
jaunty sedge
#

Need help with lr, epoche, batche

surreal quartz
# jaunty sedge Need help with lr, epoche, batche

I dont think you really need help with those params, more interesting will be the questions, how to feed the network, how to get traindata containing labels and how to set up the pipeline for this task.
To your initial question:

  • For learnrate use one of the commonly used optimizers and you will be fine. start with 0.01 and let the optimizer do the magic for you. If this does not end well, you can go for a gridsearch.
  • For epochs use a limit how long youre able to wait to get your first results, maybe 100? depending on how much computation it takes, for later (when your pipeline is set up and everything works, so you only want to improve your network) you can go for some "early stopping" mechanism and let it run till your model wont really learn much more.
  • For batchsize you can use any number you want, as long as all images and your model fit in your gpu memory. So its mostly depending on your hardware. Start with any number and check how much space is left on your GPU
jaunty sedge
#

Hey thanks for the help! I am using 640x640 images I scraped off Google maps with their lat and long saved in another csv file , I got about 80,000 of them.
I need help with using the optimiser, and generally getting the ai to do what I want it to, could you give me some pointers and maybe sudo-code?

jaunty sedge
#

I am also having issues with my current code where the loss goes to 0.000 after one batch, here is the code I am using currently:

#

`
import torch
import torch.nn as nn
import torch.optim as optim
from torchvision import transforms
from torch.utils.data import Dataset, DataLoader
import pandas as pd
from PIL import Image
import os

Import TinyViT model

from models.tiny_vit import tiny_vit_21m_224`

#

`# Define the custom dataset
class CustomDataset(Dataset):
def init(self, csv_file, root_dir, transform=None):
self.annotations = pd.read_csv(csv_file)
self.root_dir = root_dir
self.transform = transform

def __len__(self):
    return len(self.annotations)

def __getitem__(self, index):
    img_path = os.path.join(self.root_dir, f"image_{index}.jpg")
    image = Image.open(img_path).convert("RGB")
    y_label = self.annotations.iloc[index, 2]  # Assuming label is in the third column

    if self.transform:
        image = self.transform(image)

    return image, y_label

Define transformations

transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

Hyperparameters

batch_size = 32
learning_rate = 0.001
num_epochs = 25
num_classes = 1000 # Adjust based on your dataset

Load data

dataset = CustomDataset(
csv_file='C:\Users\dmitr\AiProjectTinyVit\TinyViT\Images\locations.csv',
root_dir='C:\Users\dmitr\AiProjectTinyVit\TinyViT\Images\images',
transform=transform
)
train_loader = DataLoader(dataset, batch_size=batch_size, shuffle=True)

Initialize model, loss, and optimizer

model = tiny_vit_21m_224(pretrained=True)
model.head = nn.Linear(model.head.in_features, num_classes) # Adjust for your number of classes
model = model.to('cuda' if torch.cuda.is_available() else 'cpu')

criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=learning_rate)

Training loop

for epoch in range(num_epochs):
for batch_idx, (data, targets) in enumerate(train_loader):
data = data.to('cuda' if torch.cuda.is_available() else 'cpu')
targets = targets.to('cuda' if torch.cuda.is_available() else 'cpu')

    # Forward pass
    scores = model(data)
    loss = criterion(scores, targets)`
#

` # Backward pass
optimizer.zero_grad()
loss.backward()

    # Gradient descent or adam step
    optimizer.step()

    if batch_idx % 100 == 0:
        print(f'Epoch [{epoch}/{num_epochs}] Step [{batch_idx}/{len(train_loader)}] Loss: {loss.item():.4f}')

Save the model

torch.save(model.state_dict(), 'tinyvit21m_model.pth')`

surreal quartz