Classes
Classes
Classes
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import Dataset, DataLoader
import numpy as np
# %%
class SimpleFFNetwork(nn.Module):
def __init__(self, input_length, hidden_sizes, output_size):
super(SimpleFFNetwork, self).__init__()
self.input_length = input_length
self.hidden_sizes = hidden_sizes
self.output_size = output_size
self.layers = nn.ModuleList()
prev_size = input_length
for hidden_size in hidden_sizes:
self.layers.append(nn.Linear(prev_size, hidden_size))
self.layers.append(nn.ReLU())
prev_size = hidden_size
self.layers.append(nn.Linear(hidden_size, output_size))
# %%
class SiameseNetwork(nn.Module):
# %%
class TripletDataset(Dataset):
def __len__(self):
return len(self.dataframe)
# %%
class BinaryClassifier(nn.Module):
def __init__(self, input_size, hidden_size):
super(BinaryClassifier, self).__init__()
self.fc1 = nn.Linear(input_size, hidden_size)
self.relu = nn.ReLU()
self.fc2 = nn.Linear(hidden_size, 1) # Output size is 1 for binary
classification
class SiameseBinaryClassifier(nn.Module):
def __init__(self, siamese_network):
super(SiameseBinaryClassifier, self).__init__()
self.siamese_network = siamese_network
self.fc = nn.Linear(1, 1)
# %%