id int64 0 458k | file_name stringlengths 4 119 | file_path stringlengths 14 227 | content stringlengths 24 9.96M | size int64 24 9.96M | language stringclasses 1
value | extension stringclasses 14
values | total_lines int64 1 219k | avg_line_length float64 2.52 4.63M | max_line_length int64 5 9.91M | alphanum_fraction float64 0 1 | repo_name stringlengths 7 101 | repo_stars int64 100 139k | repo_forks int64 0 26.4k | repo_open_issues int64 0 2.27k | repo_license stringclasses 12
values | repo_extraction_date stringclasses 433
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2,284,800 | model.py | dajuric_dark/dark-6/samples/4.0-NN-classification/torch/model.py | import torch
import torch.nn as nn
import os
from config import *
class MyNNBlock(nn.Module):
def __init__(self, in_dim, out_dim):
super().__init__()
self.linear = nn.Linear(in_dim, out_dim)
self.activation = nn.ReLU()
def forward(self, x):
x = self.linear(x)
x = self.... | 935 | Python | .py | 34 | 20.764706 | 53 | 0.572717 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,801 | util.py | dajuric_dark/dark-6/samples/4.0-NN-classification/dark/util.py | import numpy as np
import cv2
import dark.tensor as dt
def _draw_label(im, correct):
color = (0, 255, 0) if correct == 1 else (0, 0, 255)
cv2.circle(im, (25, 25), 5, color, -1)
def save_samples(dataset, model, filename, grid = (3, 5)):
h, w = grid
i = 0
image_rows = []
for r in range(h):
... | 1,013 | Python | .py | 26 | 29.807692 | 72 | 0.570978 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,802 | config.py | dajuric_dark/dark-6/samples/4.0-NN-classification/dark/config.py | import os
import dark.tensor as dt
print(f"Running on: {'cuda' if dt.is_cuda() else 'cpu'}")
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f"{script_dir}/model.pickle"
IM_SIZE = 28
BATCH_SIZE = 32
CLASS_COUNT = 10
EPOCHS = 5 | 250 | Python | .py | 9 | 26.666667 | 57 | 0.716667 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,803 | test.py | dajuric_dark/dark-6/samples/4.0-NN-classification/dark/test.py | import numpy as np
import cv2
import glob
import matplotlib.pyplot as plt
import dark
from model import MyNNBlock, MyNN #for deserialization
from config import *
def get_random_sample():
images = glob.glob(f"{script_dir}/../db/test/**/*.png")
imPath = np.random.choice(images, 1)[0]
im = cv2.imread(imPath)... | 860 | Python | .py | 33 | 22.30303 | 59 | 0.643902 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,804 | train.py | dajuric_dark/dark-6/samples/4.0-NN-classification/dark/train.py | import numpy as np
import dark.tensor as dt
import dark
import dark.nn as nn
from dark.optim import *
from dark.utils.transforms import *
from config import *
from rich.progress import track
from model import MyNN, get_net
from dataset import get_loaders
from util import save_samples
def train_loop(dataloader, model, ... | 2,319 | Python | .py | 60 | 32.4 | 87 | 0.614177 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,805 | dataset.py | dajuric_dark/dark-6/samples/4.0-NN-classification/dark/dataset.py |
from dark.utils.data import ImageFolder, DataLoader
from dark.utils.transforms import *
from config import *
def get_loaders():
def label_transform(l):
one_hot = np.zeros(CLASS_COUNT, dtype=np.float32)
one_hot[l] = 1
return one_hot
trTransforms = Compose(
Resize(IM_SIZE, IM_S... | 874 | Python | .py | 26 | 27.115385 | 84 | 0.64566 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,806 | model.py | dajuric_dark/dark-6/samples/4.0-NN-classification/dark/model.py | import dark
import dark.nn as nn
from dark.nn.init import default_init_weights
import os
import pickle
from config import *
class MyNNBlock(nn.Module):
def __init__(self, in_dim, out_dim):
super().__init__()
self.linear = nn.Linear(in_dim, out_dim)
self.activation = nn.ReLU()
def forw... | 1,006 | Python | .py | 36 | 21.444444 | 53 | 0.593096 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,807 | modelD.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/torch/modelD.py | from torch.nn import *
from config import *
from util import init_weights
import os
class Discriminator(Module):
def __init__(self, ndf, nc):
super().__init__()
self.nn = Sequential(
#input: nc x 64 x 64
Conv2d(nc, ndf, kernel_size=4, stride=2, padding=1),
... | 1,291 | Python | .py | 38 | 24.394737 | 73 | 0.530844 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,808 | util.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/torch/util.py | import torch
import torch.nn as nn
import cv2
def init_weights(m):
if isinstance(m, nn.Conv2d) or isinstance(m, nn.ConvTranspose2d):
nn.init.normal_(m.weight.data, 0.0, 0.02)
nn.init.zeros_(m.bias.data)
if isinstance(m, nn.BatchNorm2d):
nn.init.normal_(m.weight.data, 1.0, 0.02)
... | 959 | Python | .py | 26 | 26.923077 | 69 | 0.586047 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,809 | config.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/torch/config.py | import torch
import os
device = "cuda" if torch.cuda.is_available() else "cpu"
script_dir = os.path.dirname(os.path.realpath(__file__))
modelD_path = f"{script_dir}/modelD.pth"
modelG_path = f"{script_dir}/modelG.pth"
nz = 100
BATCH_SIZE = 40
EPOCHS = 15 | 256 | Python | .py | 9 | 27.333333 | 56 | 0.731707 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,810 | train.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/torch/train.py | import torch
from torch.utils.data import DataLoader
from torch.nn import Module, BCEWithLogitsLoss
from torch.optim import Optimizer, Adam
from modelD import Discriminator, get_netD
from modelG import Generator, get_netG
from dataset import get_loader
from util import save_samples
from rich.progress import track
from... | 2,586 | Python | .py | 65 | 33.338462 | 73 | 0.66653 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,811 | modelG.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/torch/modelG.py | import torch
from torch.nn import *
from config import *
from util import init_weights
import os
class Generator(Module):
def __init__(self, nz, ngf, nc):
super().__init__()
self.nn = Sequential(
# input: Z
ConvTranspose2d(nz, ngf * 8, kernel_size=4, stride=1, paddi... | 1,392 | Python | .py | 42 | 23.690476 | 82 | 0.529367 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,812 | dataset.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/torch/dataset.py | from torch.utils.data import DataLoader
from torchvision.datasets import ImageFolder
from torchvision.transforms import *
from config import *
def get_loader():
tr = Compose([
Resize((64, 64)),
ToTensor(),
Normalize(0.5, 0.5)
])
dataset = ImageFolder(f"{script_dir}/../db/", transfo... | 428 | Python | .py | 13 | 28.384615 | 78 | 0.699758 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,813 | modelD.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/dark/modelD.py | import dark
from dark.nn import *
import os
from util import init_weights
from config import *
class Discriminator(Module):
def __init__(self, ndf, nc):
super().__init__()
self.nn = Sequential(
#input: nc x 64 x 64
Conv2d(nc, ndf, kernel_size=4, stride=2, padding=1)... | 1,271 | Python | .py | 38 | 24.105263 | 73 | 0.534653 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,814 | util.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/dark/util.py | import dark.tensor as dt
import dark.nn as nn
from dark.nn.init import default_init_weights
import cv2
def init_weights(m):
default_init_weights(m)
if isinstance(m, nn.Conv2d) or isinstance(m, nn.ConvTranspose2d):
m.weights.data = dt.random.normal(0.0, 0.02, m.weights.data.shape)
m.bias.data =... | 1,102 | Python | .py | 28 | 29.857143 | 74 | 0.611 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,815 | config.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/dark/config.py | import dark.tensor as dt
import os
print(f"Running on: {'cuda' if dt.is_cuda() else 'cpu'}")
script_dir = os.path.dirname(os.path.realpath(__file__))
modelD_path = f"{script_dir}/modelD.pickle"
modelG_path = f"{script_dir}/modelG.pickle"
nz = 100
BATCH_SIZE = 40
EPOCHS = 15 | 276 | Python | .py | 9 | 29.555556 | 57 | 0.721805 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,816 | train.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/dark/train.py | import dark
import dark.tensor as dt
from dark.nn import Module, BCEWithLogitsLoss
from dark.optim import Optimizer, Adam
from dark.utils.data import DataLoader
from modelD import Discriminator, get_netD
from modelG import Generator, get_netG
from dataset import get_loader
from util import save_samples
from rich.progr... | 2,523 | Python | .py | 65 | 32.323077 | 80 | 0.667372 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,817 | modelG.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/dark/modelG.py | import dark
from dark.nn import *
import os
from util import init_weights
from config import *
class Generator(Module):
def __init__(self, nz, ngf, nc):
super().__init__()
self.nn = Sequential(
# input: Z
ConvTranspose2d(nz, ngf * 8, kernel_size=4, stride=1, padding... | 1,358 | Python | .py | 41 | 23.682927 | 82 | 0.528958 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,818 | dataset.py | dajuric_dark/dark-6/samples/6.0-GAN-image_gen/dark/dataset.py | from dark.utils.data import ImageFolder, DataLoader
from dark.utils.transforms import *
from config import *
def get_loader():
tr = Compose(
Resize(64, 64),
Normalize(0.5, 0.5),
ToTensorV2(),
)
dataset = ImageFolder(f"{script_dir}/../db/", imgT=tr)
data_loader = DataLoader(data... | 389 | Python | .py | 12 | 27.666667 | 79 | 0.675532 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,819 | process_db.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/db/process_db.py | import os
import cv2
from glob import glob
from rich.progress import track
script_dir = os.path.dirname(os.path.realpath(__file__))
def resize(img_folder):
im_files = sorted(glob(f"{img_folder}/*.*"))
for im_file in track(im_files, "Resizing..."):
im = cv2.imread(im_file)
im = cv2.resize(im, ... | 904 | Python | .py | 22 | 35.5 | 81 | 0.622426 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,820 | util.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/torch/util.py | import cv2
import torch
from config import *
def save_samples(dataset, model, filename, count = 5):
image_rows = []
for i in range(count):
im, true_mask = dataset[i]
im = torch.unsqueeze(im, 0).type(torch.float32)
pred_mask = model(im.to(device)).detach().cpu()
pred_mask = tor... | 847 | Python | .py | 18 | 40.444444 | 121 | 0.623786 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,821 | config.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/torch/config.py | import os
import torch
import albumentations as A
import albumentations.pytorch.transforms as AT
IM_SIZE = 64
BATCH_SIZE = 24
EPOCHS = 3
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using: {device}")
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f"{script_dir}/model.pth"
... | 554 | Python | .py | 22 | 22.636364 | 56 | 0.705323 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,822 | train.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/torch/train.py | import torch.nn as nn
from torch.optim import Adam
from rich.progress import track
from dataset import get_loaders
from model import UNet, get_net
from util import save_samples
from config import *
def train_loop(dataloader, model, loss_fn, optimizer):
model.train()
size = len(dataloader.dataset)
for batc... | 1,848 | Python | .py | 49 | 31.081633 | 87 | 0.608032 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,823 | dataset.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/torch/dataset.py | import torch
from torch.utils.data import Dataset, DataLoader
from config import *
from glob import glob
from pathlib import Path
import cv2
class CarvanaDataset(Dataset):
def __init__(self, im_folder, transform=None):
self.im_files = sorted(glob(f"{im_folder}/*.jpg"))
self.transform = transform
... | 1,327 | Python | .py | 33 | 33.272727 | 78 | 0.648163 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,824 | model.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/torch/model.py | import torch
import torch.nn as nn
import os
from config import *
class UNet(nn.Module):
def __init__(self, in_channels, out_channels):
super().__init__()
features = [32, 64, 128, 256]
# down
self.down_blocks = nn.ModuleList()
self.down_reducs = nn.ModuleList()
for ... | 2,188 | Python | .py | 65 | 24.276923 | 90 | 0.545759 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,825 | util.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/dark/util.py | import dark.tensor as dt
import cv2
def save_samples(dataset, model, filename, count = 5):
image_rows = []
for i in range(count):
im, true_mask = dataset[i]
im, true_mask = dt.asarray(im), dt.asarray(true_mask)
im = dt.expand_dims(im, 0)
pred_mask = model(im).... | 899 | Python | .py | 19 | 39.263158 | 112 | 0.601399 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,826 | config.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/dark/config.py | import os
import dark.tensor as dt
from dark.utils.transforms import *
IM_SIZE = 64
BATCH_SIZE = 24
EPOCHS = 3
print(f"Running on: {'cuda' if dt.is_cuda() else 'cpu'}")
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f"{script_dir}/model.pth"
trTransforms = Compose(
Resize(IM_SIZE, IM_SIZE)... | 545 | Python | .py | 22 | 22 | 57 | 0.680769 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,827 | train.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/dark/train.py | import dark
import dark.nn as nn
from dark.optim import *
from rich.progress import track
from dataset import get_loaders
from model import UNet, get_net
from util import save_samples
from config import *
def train_loop(dataloader, model, loss_fn, optimizer):
model.train()
size = len(dataloader.dataset)
f... | 1,761 | Python | .py | 48 | 30.25 | 87 | 0.61392 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,828 | dataset.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/dark/dataset.py | from dark.utils.data import Dataset, DataLoader
import numpy as np
import random
from datetime import datetime
import cv2
from config import *
from glob import glob
from pathlib import Path
import cv2
class CarvanaDataset(Dataset):
def __init__(self, im_folder, transform=None):
self.im_files = sorted(glob(... | 1,727 | Python | .py | 45 | 31.666667 | 78 | 0.641396 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,829 | model.py | dajuric_dark/dark-6/samples/6.1-UNet-segmentation/dark/model.py | import dark
import dark.nn as nn
from dark.nn.init import default_init_weights
import os
from config import *
# adopted from: https://medium.com/analytics-vidhya/creating-a-very-simple-u-net-model-with-pytorch-for-semantic-segmentation-of-satellite-images-223aa216e705
class UNet(nn.Module):
def __init__(self, in_c... | 2,446 | Python | .py | 68 | 26.808824 | 158 | 0.575771 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,830 | util.py | dajuric_dark/dark-6/samples/3.0-Func-NN-regression/torch/util.py | import torch
import numpy as np
import matplotlib.pyplot as plt
ax = None
def plot(X, Y, eval_func):
global ax
if ax is None:
plt.ion()
plt.show()
ax = plt.figure().add_subplot(projection='3d')
ax.cla()
X_curve = torch.meshgrid(torch.linspace(0, 1, 25), to... | 641 | Python | .py | 18 | 29.611111 | 88 | 0.625213 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,831 | train.py | dajuric_dark/dark-6/samples/3.0-Func-NN-regression/torch/train.py | import os
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
import torch
import torch.nn as nn
import torch.optim as optim
import matplotlib.pyplot as plt
from model import get_net
from util import *
from dataset import *
X, y = get_data()
X = normalize_data(X); y = normalize_data(y)
X = torch.tensor... | 736 | Python | .py | 26 | 25.461538 | 84 | 0.67482 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,832 | dataset.py | dajuric_dark/dark-6/samples/3.0-Func-NN-regression/torch/dataset.py | import random
import numpy as np
def get_data():
def f(x, y):
return np.sin(np.sqrt(x ** 2 + y ** 2))
x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
X = X.reshape(-1, 1); Y = Y.reshape(-1, 1)
data = np.concatenate((X, Y), axis=1)
va... | 523 | Python | .py | 18 | 24.222222 | 48 | 0.548387 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,833 | model.py | dajuric_dark/dark-6/samples/3.0-Func-NN-regression/torch/model.py | import torch
import torch.nn as nn
class MyNNBlock(nn.Module):
def __init__(self, in_dim, out_dim):
super().__init__()
self.linear = nn.Linear(in_dim, out_dim)
self.activation = nn.LeakyReLU()
def forward(self, x):
x = self.linear(x)
x = self.activation(x)
retu... | 762 | Python | .py | 27 | 21.074074 | 48 | 0.557559 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,834 | util.py | dajuric_dark/dark-6/samples/3.0-Func-NN-regression/dark/util.py | import dark.tensor as dt
import numpy as np
import matplotlib.pyplot as plt
ax = None
def plot(X, Y, eval_func):
global ax
if ax is None:
plt.ion()
plt.show()
ax = plt.figure().add_subplot(projection='3d')
ax.cla()
X_curve = np.meshgrid(np.linspace(0, 1, 2... | 611 | Python | .py | 19 | 26.263158 | 70 | 0.616906 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,835 | train.py | dajuric_dark/dark-6/samples/3.0-Func-NN-regression/dark/train.py | import os
os.environ["USE_CPU"] = "True"
import dark
import dark.tensor as dt
import dark.nn as nn
import dark.optim as optim
import matplotlib.pyplot as plt
from model import get_net
from util import *
from dataset import *
X, y = get_data()
X = normalize_data(X); y = normalize_data(y)
model = get_net()
model.tra... | 636 | Python | .py | 26 | 21.730769 | 46 | 0.69398 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,836 | dataset.py | dajuric_dark/dark-6/samples/3.0-Func-NN-regression/dark/dataset.py | import random
import numpy as np
def get_data():
def f(x, y):
return np.sin(np.sqrt(x ** 2 + y ** 2))
x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
X = X.reshape(-1, 1); Y = Y.reshape(-1, 1)
data = np.concatenate((X, Y), axis=1)
va... | 523 | Python | .py | 18 | 24.222222 | 48 | 0.548387 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,837 | model.py | dajuric_dark/dark-6/samples/3.0-Func-NN-regression/dark/model.py | import dark
import dark.nn as nn
from dark.nn.init import default_init_weights
class MyNNBlock(nn.Module):
def __init__(self, in_dim, out_dim):
super().__init__()
self.linear = nn.Linear(in_dim, out_dim)
self.activation = nn.LeakyReLU()
def forward(self, x):
x = self.linear(x)... | 841 | Python | .py | 29 | 22.172414 | 48 | 0.580726 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,838 | process_db.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/db/process_db.py | import os
from pathlib import Path
import json
import numpy as np
import cv2
from rich.progress import track
import mediapipe as mp
mp_face_detection = mp.solutions.face_detection
script_dir = os.path.dirname(os.path.realpath(__file__))
def read_keypoints(json_file):
data = json.load(open(json_file, "r"))
dat... | 2,689 | Python | .py | 68 | 33.367647 | 95 | 0.624951 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,839 | util.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/torch/util.py | import torch
import cv2
import numpy as np
def _draw_keypoints(im, keypoints, color):
imH, imW, _ = im.shape
for x, y in keypoints.reshape(-1, 2):
x = int(x * imW)
y = int(y * imH)
cv2.circle(im, (x, y), 3, color, -1)
def save_samples(dataset, model, filename, grid = (3, 5), device =... | 1,077 | Python | .py | 28 | 29.392857 | 81 | 0.56182 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,840 | config.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/torch/config.py | import os
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using: {device}")
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f"{script_dir}/model.pth"
IM_SIZE = 96
KEYPOINT_COUNT = 68 * 2
BATCH_SIZE = 64
EPOCHS = 15 | 268 | Python | .py | 10 | 25.6 | 56 | 0.722656 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,841 | test_camera.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/torch/test_camera.py | import torch
from model import Resnet18
import numpy as np
import os
import cv2
import mediapipe as mp
mp_face_detection = mp.solutions.face_detection
mp_drawing = mp.solutions.drawing_utils
device = 'cuda' if torch.cuda.is_available() else 'cpu'
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f... | 2,686 | Python | .py | 70 | 32.471429 | 95 | 0.613344 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,842 | train.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/torch/train.py | import torch
import torch.nn as nn
from torchvision.transforms import *
import torch.optim as optim
from rich.progress import track
from model import Resnet18, get_net
from util import save_samples
from dataset import get_loaders
from config import *
def train_loop(train_loader, model, criterion, optimizer):
trai... | 1,993 | Python | .py | 55 | 29.981818 | 97 | 0.620636 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,843 | dataset.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/torch/dataset.py | from torch.utils.data import Dataset
from torch.utils.data import DataLoader
import json
import numpy as np
import cv2
import albumentations as A
import albumentations.pytorch.transforms as AT
from config import *
import random
from glob import glob
class KeypointDataset(Dataset):
def __init__(self, kp_files, tran... | 2,239 | Python | .py | 56 | 32.982143 | 77 | 0.643893 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,844 | model.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/torch/model.py | import torch
import torch.nn as nn
import os
from config import *
class Block(nn.Module):
def __init__(self, in_ch, out_ch, stride=1):
super(Block, self).__init__()
self.downsample = self.get_identity_downsample(in_ch, out_ch) if stride != 1 else None
self.conv1 = nn.Conv2d(in... | 2,923 | Python | .py | 78 | 27.115385 | 94 | 0.571535 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,845 | util.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/dark/util.py | import dark
import cv2
import numpy as np
def _draw_keypoints(im, keypoints, color):
imH, imW, _ = im.shape
for x, y in keypoints.reshape(-1, 2):
x = int(x * imW)
y = int(y * imH)
cv2.circle(im, (x, y), 3, color, -1)
def save_samples(dataset, model, filename, grid = (3, 5)):
h, w... | 1,034 | Python | .py | 28 | 27.857143 | 71 | 0.557851 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,846 | config.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/dark/config.py | import os
import dark.tensor as dt
import dark.utils.transforms as T
import dark.utils.point_transforms as P
print(f"Running on: {'cuda' if dt.is_cuda() else 'cpu'}")
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f"{script_dir}/model.pth"
IM_SIZE = 96
KEYPOINT_COUNT = 68 * 2
BATCH_SIZE = 64
EP... | 929 | Python | .py | 34 | 24.264706 | 64 | 0.670045 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,847 | test_camera.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/dark/test_camera.py | import dark
import dark.tensor as dt
from model import Resnet18
import numpy as np
import os
import cv2
import mediapipe as mp
mp_face_detection = mp.solutions.face_detection
mp_drawing = mp.solutions.drawing_utils
print(f"Running on: {'cuda' if dt.is_cuda() else 'cpu'}")
script_dir = os.path.dirname(os.path.realpath... | 2,643 | Python | .py | 70 | 31.857143 | 95 | 0.609524 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,848 | train.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/dark/train.py | from rich.progress import track
import dark
import dark.nn as nn
import dark.optim as optim
from model import Resnet18, get_net
from util import save_samples
from dataset import get_loaders
from config import *
def train_loop(train_loader, model, criterion, optimizer):
train_loss = 0.0
model.train()
for b... | 1,950 | Python | .py | 52 | 30.884615 | 84 | 0.622854 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,849 | dataset.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/dark/dataset.py | from dark.utils.data import Dataset, DataLoader
from config import *
import json
import numpy as np
import cv2
import random
from datetime import datetime
from glob import glob
class KeypointDataset(Dataset):
def __init__(self, kp_files, im_transform, kp_transform):
self.kp_files = kp_files
self.im... | 2,574 | Python | .py | 65 | 32.707692 | 90 | 0.625554 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,850 | model.py | dajuric_dark/dark-6/samples/5.1-ResNet-regression/dark/model.py | import dark
import dark.nn as nn
from dark.nn.init import default_init_weights
import os
import pickle
from config import *
class Block(nn.Module):
def __init__(self, in_ch, out_ch, stride=1):
super(Block, self).__init__()
self.downsample = self.get_identity_downsample(in_ch, out_ch) if stride... | 3,042 | Python | .py | 81 | 27.518519 | 94 | 0.583006 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,851 | util.py | dajuric_dark/dark-6/samples/1.1-Func-optimization/torch/util.py | import numpy as np
import matplotlib.pyplot as plt
ax = None
def plot(eval_func, range, x_param):
global ax
if ax is None:
plt.ion()
plt.show()
X_curve = np.linspace(range[0], range[1], 100).reshape(-1, 1)
Y_curve = eval_func(X_curve).reshape(-1, 1)
plt.plot(X_c... | 434 | Python | .py | 14 | 25.214286 | 64 | 0.637056 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,852 | train.py | dajuric_dark/dark-6/samples/1.1-Func-optimization/torch/train.py | import os
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
import torch
from util import *
def eval_func(x):
fx = torch.add(torch.mul(2, torch.pow(x, 2)), 5) #2*x^2 + 5
return fx
x = torch.tensor(10.0, requires_grad=True)
for _ in range(15):
print(f"Value of x is: {x.data.item():2.1f}")
fx = eval_fu... | 537 | Python | .py | 16 | 29.3125 | 71 | 0.634578 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,853 | util.py | dajuric_dark/dark-6/samples/1.1-Func-optimization/dark/util.py | import numpy as np
import matplotlib.pyplot as plt
ax = None
def plot(eval_func, range, x_param):
global ax
if ax is None:
plt.ion()
plt.show()
X_curve = np.linspace(range[0], range[1], 100).reshape(-1, 1)
Y_curve = eval_func(X_curve).reshape(-1, 1)
plt.plot(X_c... | 438 | Python | .py | 14 | 25.214286 | 64 | 0.637056 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,854 | train.py | dajuric_dark/dark-6/samples/1.1-Func-optimization/dark/train.py | import os
os.environ["USE_CPU"] = "True"
import dark
from util import *
def eval_func(x):
fx = dark.add(dark.mul(2, dark.pow(x, 2)), 5) #2*x^2 + 5
return fx
x = dark.Parameter(10.0)
for _ in range(15):
print(f"Value of x is: {x.data.item():2.1f}")
fx = eval_func(x)
fx.backward() #calc grad... | 487 | Python | .py | 16 | 26.1875 | 61 | 0.616558 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,855 | test_conv2d.py | dajuric_dark/dark-6/tests/test_conv2d.py | import os
os.environ["USE_CPU"] = "True"
import dark
import dark.tensor as dt
def approx_grad(X, function, eps=1e-6):
grad = dt.zeros_like(X)
for i in range(len(X)):
X[i] += eps
fn_2 = function(X)
X[i] -= 2 * eps
fn_1 = function(X)
grad[i] = (fn_2... | 1,381 | Python | .py | 32 | 37.25 | 129 | 0.612606 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,856 | testConv2d.py | dajuric_dark/dark-6/tests/testConv2d.py | import numpy as np
import random
import os
random.seed(0)
np.random.seed(0)
im = np.random.randint(-16, +16, size=(2, 2, 9, 9)).astype(np.float64)
k = np.random.randint(-16, +16, size=(3, 2, 3, 3)).astype(np.float64)
#---------------------------
import torch as tt
import torch.nn as nn
st = tt.tensor(im, requ... | 1,079 | Python | .py | 30 | 34.533333 | 105 | 0.639961 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,857 | testConv2dtranspose.py | dajuric_dark/dark-6/tests/testConv2dtranspose.py | import numpy as np
import random
import os
random.seed(0)
np.random.seed(0)
im = np.random.randint(-16, +16, size=(4, 1, 32, 32)).astype(np.float64)
k = np.random.randint(-16, +16, size=(2, 1, 3, 3)).astype(np.float64); k = k.transpose(1, 0, 2, 3)
#---------------------------
import torch as tt
import torch.nn... | 1,130 | Python | .py | 30 | 36.233333 | 105 | 0.642134 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,858 | testUpsample2d.py | dajuric_dark/dark-6/tests/testUpsample2d.py | import numpy as np
import random
import os
random.seed(0)
np.random.seed(0)
im = np.random.randint(-16, +16, size=(1, 3, 2, 2)).astype(np.float64)
#---------------------------
import torch as tt
import torch.nn as nn
st = tt.tensor(im, requires_grad=True)
tRes = nn.functional.interpolate(st, scale_factor=3, mode=... | 828 | Python | .py | 26 | 30.346154 | 105 | 0.66033 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,859 | testCNN.py | dajuric_dark/dark-6/tests/testCNN.py | import numpy as np
import random
random.seed(1)
np.random.seed(1)
X = np.random.randint(-16, +16, size=(1, 3, 9, 9)).astype(np.float32)
# -----------------------------------------------------------------------
#import os
#os.environ["USE_CPU"] = "True"
import dark
import dark.nn as nn
import dark.optim as optim
imp... | 2,763 | Python | .py | 89 | 26 | 107 | 0.59017 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,860 | test_conv2dtranspose.py | dajuric_dark/dark-6/tests/test_conv2dtranspose.py | #import os
#os.environ["USE_CPU"] = "True"
import dark
import dark.tensor as dt
def approx_grad(X, function, eps=1e-6):
grad = dt.zeros_like(X)
for i in range(len(X)):
X[i] += eps
fn_2 = function(X)
X[i] -= 2 * eps
fn_1 = function(X)
grad[i] = (fn... | 1,531 | Python | .py | 37 | 35.405405 | 122 | 0.609059 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,861 | testMaxPool2d.py | dajuric_dark/dark-6/tests/testMaxPool2d.py | import numpy as np
import random
import os
random.seed(0)
np.random.seed(0)
im = np.random.randint(-16, +16, size=(1, 3, 2, 2)).astype(np.float64)
#---------------------------
import torch as tt
import torch.nn as nn
st = tt.tensor(im, requires_grad=True)
tRes = nn.functional.max_pool2d(st, kernel_size=2)
tRes = ... | 815 | Python | .py | 26 | 29.846154 | 105 | 0.657216 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,862 | __init__.py | dajuric_dark/dark-6/dark/__init__.py | from .core.operations import *
from .core.autodiff import *
from .utils.serialization import save, load | 103 | Python | .py | 3 | 33.666667 | 43 | 0.811881 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,863 | optimizers.py | dajuric_dark/dark-6/dark/optim/optimizers.py |
import dark.tensor as dt
class Optimizer():
def __init__(self, parameters):
self.parameters = parameters
def step(self):
raise NotImplementedError()
def zero_grad(self):
for p in self.parameters:
p.zero_grad()
class SGD(Optimizer):
def __init__(self, parameters,... | 2,226 | Python | .py | 54 | 31.259259 | 115 | 0.551643 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,864 | transforms.py | dajuric_dark/dark-6/dark/utils/transforms.py | import cv2
import numpy as np
import random
from .util import max_inscribed_rect
class Transform():
def __init__(self):
pass
def __call__(self, im):
raise Exception("Not implemented")
class Compose():
def __init__(self, *transforms):
self.transforms = transforms
def __call__(... | 5,328 | Python | .py | 144 | 28.354167 | 90 | 0.553511 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,865 | util.py | dajuric_dark/dark-6/dark/utils/util.py | import math
# https://stackoverflow.com/questions/5789239/calculate-largest-inscribed-rectangle-in-a-rotated-rectangle
def max_inscribed_rect(w, h, angle):
angle = math.radians(angle)
quadrant = int(math.floor(angle / (math.pi / 2))) & 3
sign_alpha = angle if ((quadrant & 1) == 0) else math.pi - angle
... | 801 | Python | .py | 17 | 42.411765 | 106 | 0.617761 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,866 | point_transforms.py | dajuric_dark/dark-6/dark/utils/point_transforms.py | import random
import numpy as np
from .util import max_inscribed_rect
class PointTransform():
def __call__(self, pts, im_shape):
pass
class Compose():
def __init__(self, *transforms):
self.transforms = transforms
def __call__(self, pts, im_shape):
t_pts = pts
t_shape =... | 1,897 | Python | .py | 55 | 25.327273 | 66 | 0.523596 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,867 | serialization.py | dajuric_dark/dark-6/dark/utils/serialization.py | import os
import pickle
from copy import deepcopy
from .. import tensor as dt
def _dt_to_numpy(obj):
if "cupy.ndarray" in str(obj.__class__):
return obj.get()
return obj
def _numpy_to_dt(obj):
if "numpy.ndarray" in str(obj.__class__):
return dt.asarray(obj)
return obj
def ... | 1,243 | Python | .py | 39 | 25.769231 | 67 | 0.614539 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,868 | data.py | dajuric_dark/dark-6/dark/utils/data.py | import os
from glob import glob
import math
import numpy as np
import cv2
class Dataset():
def __init__(self):
pass
def __len__(self):
raise NotImplementedError()
def __getitem__(self, index):
raise NotImplementedError()
class ImageFolder(Dataset):
def __init__(self, root_fo... | 3,615 | Python | .py | 90 | 30.566667 | 91 | 0.603872 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,869 | ops.py | dajuric_dark/dark-6/dark/tensor/ops.py | import os
use_cpu = os.environ.get("USE_CPU") in ["1", "True"]
_is_cuda = False
try:
if use_cpu: raise Exception("CPU forced")
from cupy import *
from .gpu.conv import conv2d, conv2d_grad
from .gpu.pool import max_pool2d, max_unpool2d
_is_cuda = True
except:
from numpy import *
from .c... | 714 | Python | .py | 26 | 22.653846 | 52 | 0.646617 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,870 | pool.py | dajuric_dark/dark-6/dark/tensor/cpu/pool.py | # https://agustinus.kristia.de/techblog/2016/07/18/convnet-maxpool-layer/
# https://hackmd.io/@machine-learning/blog-post-cnnumpy-slow
import numpy as np
from numba import njit, prange
@njit()
def _max_pool2d_im(X, size, stride, out, out_idx):
oh, ow = out.shape
for h in range(oh):
h_start = h * ... | 2,138 | Python | .py | 57 | 29.754386 | 80 | 0.55164 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,871 | conv.py | dajuric_dark/dark-6/dark/tensor/cpu/conv.py | import numpy as np
from numba import njit, prange
@njit()
def _pad(tensor, padding):
sb, sc, sh, sw = tensor.shape
padded = np.zeros((sb, sc, sh + padding*2, sw + padding*2))
padded[:, :, padding: sh + padding, padding: sw + padding] = tensor
return padded
@njit()
def _conv2d_im(X, W, stride, ou... | 2,395 | Python | .py | 60 | 31.75 | 76 | 0.53976 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,872 | util.py | dajuric_dark/dark-6/dark/tensor/gpu/util.py | import cupy as cp
def get_indices(x_shape, field_height, field_width, padding=1, stride=1):
N, C, H, W = x_shape
#assert (H + 2 * padding - field_height) % stride == 0
#assert (W + 2 * padding - field_height) % stride == 0
out_height = int((H + 2 * padding - field_height) / stride + 1)
out_width =... | 1,859 | Python | .py | 35 | 47.942857 | 78 | 0.621262 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,873 | pool.py | dajuric_dark/dark-6/dark/tensor/gpu/pool.py | # refs: https://agustinus.kristia.de/techblog/2016/07/18/convnet-maxpool-layer/
import cupy as cp
from .util import im2col, col2im
def max_pool2d(X, size, stride):
n, d, h, w = X.shape
h_out = (h - size) / stride + 1
w_out = (w - size) / stride + 1
if not w_out.is_integer() or not h_out.is_integer():... | 1,089 | Python | .py | 25 | 38.72 | 79 | 0.625475 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,874 | conv.py | dajuric_dark/dark-6/dark/tensor/gpu/conv.py | import cupy as cp
from .util import im2col, col2im
def conv2d(X, W, stride, padding):
n_filters, d_filter, h_filter, w_filter = W.shape
n_x, d_x, h_x, w_x = X.shape
h_out = (h_x - h_filter + 2 * padding) // stride + 1
w_out = (w_x - w_filter + 2 * padding) // stride + 1
# if not h_out.is_integer(... | 1,180 | Python | .py | 26 | 40.576923 | 84 | 0.630796 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,875 | autodiff.py | dajuric_dark/dark-6/dark/core/autodiff.py | import dark.tensor as dt
class Node():
op = None
inputs = []
data = None
requires_grad = True
_grad = None
def __init__(self, val):
self.data = dt.asarray(val)
if len(self.data.shape) == 0: self.data = self.data.reshape((1, 1))
def backward(self):
if self.grad is ... | 2,807 | Python | .py | 89 | 21.876404 | 112 | 0.545593 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,876 | utils.py | dajuric_dark/dark-6/dark/core/utils.py | import dark.tensor as dt
import numpy as np
def reduce_sum(result, target_shape):
dim_diff = result.ndim - len(target_shape)
if dim_diff < 0:
return result.reshape(target_shape)
# sum all leading dimensions
# except leading dimensions, sum all axis that are equal to 1, count from right
... | 553 | Python | .py | 13 | 37.384615 | 93 | 0.70566 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,877 | operations.py | dajuric_dark/dark-6/dark/core/operations.py | from .autodiff import Operation
from .utils import *
import dark.tensor as dt
# ------ scalar ------
class AbsoluteValue(Operation):
def forward(self, x):
return dt.abs(x)
def backward(self, dldy, y, x):
gz = (x > 0)
lz = dt.logical_not(gz)
return [dldy * gz - dldy * lz]
clas... | 10,874 | Python | .py | 288 | 30.413194 | 137 | 0.612592 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,878 | module.py | dajuric_dark/dark-6/dark/nn/module.py | from dark import Parameter, Node, Constant
class Module():
def __init__(self):
self._modules = {}
self._parameters = {}
def forward(self, *x):
pass
def __call__(self, *x):
x = [(Constant(p) if not isinstance(p, Node) else p) for p in x]
return self.forward(*x)
... | 2,248 | Python | .py | 69 | 23.478261 | 74 | 0.550257 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,879 | init.py | dajuric_dark/dark-6/dark/nn/init.py | import dark.tensor as dt
import dark.nn as nn
from dark import *
def _calc_in_out_dims(t_shape):
assert len(t_shape) > 1
in_maps = t_shape[1]
out_maps = t_shape[0]
if len(t_shape) > 2:
s = dt.prod(dt.array(t_shape[2:]))
in_maps *= s
out_maps *= s
return in_maps, out... | 1,105 | Python | .py | 30 | 31.366667 | 69 | 0.629595 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,880 | __init__.py | dajuric_dark/dark-6/dark/nn/__init__.py | from .init import *
from .module import *
from .modules import *
from .losses import * | 88 | Python | .py | 4 | 21.25 | 22 | 0.741176 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,881 | losses.py | dajuric_dark/dark-6/dark/nn/losses.py | import dark
from .module import Module
from .modules import Sigmoid, Softmax
class MSELoss(Module):
def __init__(self):
super().__init__()
def forward(self, predictions, targets):
loss = dark.subtract(predictions, targets)
loss = dark.pow(loss, 2)
loss = dark.mean(loss)
... | 1,191 | Python | .py | 32 | 29.84375 | 107 | 0.6295 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,882 | modules.py | dajuric_dark/dark-6/dark/nn/modules.py | import dark.tensor as dt
from dark import Parameter, Node, Constant
import dark
from .module import *
class ZeroParam(Parameter):
def __init__(self, *shape):
val = dt.zeros(shape)
super().__init__(val)
class Flatten(Module):
def __init__(self):
super().__init__()
pass
def... | 5,024 | Python | .py | 120 | 33.841667 | 147 | 0.605915 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,883 | setup.py | dajuric_dark/dark-2/setup.py | from setuptools import setup
setup(
name="dark",
description="",
version="2.0",
packages=["dark"],
package_dir={"dark": "dark"},
install_requires = []
)
| 182 | Python | .py | 9 | 16 | 33 | 0.598837 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,884 | util.py | dajuric_dark/dark-2/samples/2.0-Func-logistic-regression/torch/util.py | import numpy as np
import matplotlib.pyplot as plt
ax = None
def plot(X, Y, eval_func):
global ax
if ax is None:
plt.ion()
plt.show()
ax = plt.figure().add_subplot(projection='3d')
ax.cla()
X_curve = np.meshgrid(np.linspace(0, 1, 25), np.linspace(0, 1, 25)... | 555 | Python | .py | 17 | 26.352941 | 70 | 0.605578 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,885 | train.py | dajuric_dark/dark-2/samples/2.0-Func-logistic-regression/torch/train.py | import os
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
import numpy as np
import torch
import matplotlib.pyplot as plt
from util import *
from dataset import *
def sigmoid(x):
den = torch.add(1, torch.exp(torch.neg(x)))
return torch.div(1, den)
def bce_loss(predictions, targets):
lossA = torch.mul(targets... | 1,249 | Python | .py | 34 | 33.117647 | 92 | 0.690058 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,886 | dataset.py | dajuric_dark/dark-2/samples/2.0-Func-logistic-regression/torch/dataset.py | import random
import torch
def get_data():
X = []; Y = []
for i in range(100):
x_1 = random.random()
x_2 = random.random()
y = 1 if x_1 < 0.5 else 0 #split
X.append((x_1, x_2))
Y.append([y])
X = torch.tensor(X, dtype=torch.float64)
Y = torch.tensor(Y,... | 357 | Python | .py | 13 | 20.923077 | 44 | 0.548193 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,887 | util.py | dajuric_dark/dark-2/samples/2.0-Func-logistic-regression/dark/util.py | import numpy as np
import matplotlib.pyplot as plt
ax = None
def plot(X, Y, eval_func):
global ax
if ax is None:
plt.ion()
plt.show()
ax = plt.figure().add_subplot(projection='3d')
ax.cla()
X_curve = np.meshgrid(np.linspace(0, 1, 25), np.linspace(0, 1, 25)... | 555 | Python | .py | 17 | 26.352941 | 70 | 0.605578 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,888 | train.py | dajuric_dark/dark-2/samples/2.0-Func-logistic-regression/dark/train.py | import numpy as np
import dark
from dark import Parameter
import matplotlib.pyplot as plt
from util import *
from dataset import *
def sigmoid(x):
den = dark.add(1, dark.exp(dark.neg(x)))
return dark.div(1, den)
def bce_loss(predictions, targets):
lossA = dark.mul(targets, dark.log(predictions))
lossB... | 1,142 | Python | .py | 33 | 30.939394 | 89 | 0.682234 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,889 | dataset.py | dajuric_dark/dark-2/samples/2.0-Func-logistic-regression/dark/dataset.py | import random
import numpy as np
def get_data():
X = []; Y = []
for i in range(100):
x_1 = random.random()
x_2 = random.random()
y = 1 if x_1 < 0.5 else 0 #split
X.append((x_1, x_2))
Y.append([y])
X = np.array(X); Y = np.array(Y)
return X, Y | 310 | Python | .py | 12 | 19.166667 | 40 | 0.503497 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,890 | eval.py | dajuric_dark/dark-2/samples/1.0-Func-derivation/torch/eval.py | import os
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
import torch
import matplotlib.pyplot as plt
def calc_points(range = (-15, 15)):
x = torch.linspace(range[0], range[1], 50).reshape(1, -1)
x = torch.tensor(x, requires_grad=True)
fx = torch.add(torch.mul(2, torch.pow(x, 2)), 5) #2*x^2 + 5
#fx ... | 761 | Python | .py | 21 | 32.285714 | 105 | 0.621585 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,891 | eval.py | dajuric_dark/dark-2/samples/1.0-Func-derivation/dark/eval.py | import dark
import dark.tensor as dt
import matplotlib.pyplot as plt
def calc_points(range = (-15, 15)):
x = dt.linspace(range[0], range[1], 50).reshape(1, -1)
x = dark.Parameter(x)
fx = dark.add(dark.mul(2, dark.pow(x, 2)), 5) #2*x^2 + 5
#fx = dark.div(dark.mul(dark.tanh(x), dark.pow(x, 2)), dark... | 671 | Python | .py | 20 | 29.5 | 100 | 0.610248 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,892 | util.py | dajuric_dark/dark-2/samples/1.1-Func-optimization/torch/util.py | import numpy as np
import matplotlib.pyplot as plt
ax = None
def plot(eval_func, range, x_param):
global ax
if ax is None:
plt.ion()
plt.show()
X_curve = np.linspace(range[0], range[1], 100).reshape(-1, 1)
Y_curve = eval_func(X_curve).reshape(-1, 1)
plt.plot(X_c... | 434 | Python | .py | 14 | 25.214286 | 64 | 0.637056 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,893 | train.py | dajuric_dark/dark-2/samples/1.1-Func-optimization/torch/train.py | import os
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
import torch
from util import *
def eval_func(x):
fx = torch.add(torch.mul(2, torch.pow(x, 2)), 5) #2*x^2 + 5
return fx
x = torch.tensor(10.0, requires_grad=True)
for _ in range(15):
print(f"Value of x is: {x.data.item():2.1f}")
fx = eval_fu... | 537 | Python | .py | 16 | 29.3125 | 71 | 0.634578 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,894 | util.py | dajuric_dark/dark-2/samples/1.1-Func-optimization/dark/util.py | import numpy as np
import matplotlib.pyplot as plt
ax = None
def plot(eval_func, range, x_param):
global ax
if ax is None:
plt.ion()
plt.show()
X_curve = np.linspace(range[0], range[1], 100).reshape(-1, 1)
Y_curve = eval_func(X_curve).reshape(-1, 1)
plt.plot(X_c... | 438 | Python | .py | 14 | 25.214286 | 64 | 0.637056 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,895 | train.py | dajuric_dark/dark-2/samples/1.1-Func-optimization/dark/train.py | import os
os.environ["USE_CPU"] = "True"
import dark
from util import *
def eval_func(x):
fx = dark.add(dark.mul(2, dark.pow(x, 2)), 5) #2*x^2 + 5
return fx
x = dark.Parameter(10.0)
for _ in range(15):
print(f"Value of x is: {x.data.item():2.1f}")
fx = eval_func(x)
fx.backward() #calc grad... | 487 | Python | .py | 16 | 26.1875 | 61 | 0.616558 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,896 | ops.py | dajuric_dark/dark-2/dark/tensor/ops.py | from numpy import *
seterr(over='raise')
def unsqueeze(x, axis):
return expand_dims(x, axis)
def sigmoid(x):
return 1 / (1 + exp(-x)) | 147 | Python | .py | 6 | 21.333333 | 31 | 0.669118 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,897 | autodiff.py | dajuric_dark/dark-2/dark/core/autodiff.py | import dark.tensor as dt
class Node():
op = None
inputs = []
data = None
requires_grad = True
_grad = None
def __init__(self, val):
self.data = dt.asarray(val)
if len(self.data.shape) == 0: self.data = self.data.reshape((1, 1))
def backward(self):
if self.grad is ... | 2,807 | Python | .py | 89 | 21.876404 | 112 | 0.545593 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,898 | utils.py | dajuric_dark/dark-2/dark/core/utils.py | import dark.tensor as dt
def reduce_sum(result, target_shape):
dim_diff = result.ndim - len(target_shape)
if dim_diff < 0:
return result.reshape(target_shape)
# sum all leading dimensions
# except leading dimensions, sum all axis that are equal to 1, count from right
dim0 = tuple(range... | 534 | Python | .py | 12 | 39 | 93 | 0.701172 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,899 | operations.py | dajuric_dark/dark-2/dark/core/operations.py | from .autodiff import Operation
from .utils import *
import dark.tensor as dt
# ------ scalar ------
class AbsoluteValue(Operation):
def forward(self, x):
return dt.abs(x)
def backward(self, dldy, y, x):
gz = (x > 0)
lz = dt.logical_not(gz)
return [dldy * gz - dldy * lz]
clas... | 5,357 | Python | .py | 169 | 25.402367 | 89 | 0.601347 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |