Skip to content

Instantly share code, notes, and snippets.

@subhadarship
subhadarship / collate_fn_example.py
Created February 27, 2020 04:19
collate_fn for PyTorch DataLoader
import torch
from torch.utils.data import Dataset, DataLoader
import numpy as np
class MyDataset(Dataset):
def __init__(self):
x = np.random.rand(1000, 3) # 1000 3-dim samples
self.x = [x[i].tolist() for i in range(1000)]
y = np.random.randint(low=0, high=2, size=(1000,))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@subhadarship
subhadarship / net_using_pytorch.py
Last active May 10, 2024 08:59
simple neural net using pytorch
import torch
from torch import nn
from torch.utils.data import Dataset, DataLoader
from tqdm import tqdm
import matplotlib.pyplot as plt
class MyDataset(Dataset):
def __init__(self):