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,700 | util.py | dajuric_dark/dark-5/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,701 | train.py | dajuric_dark/dark-5/samples/2.0-Func-logistic-regression/dark/train.py | import os
os.environ["USE_CPU"] = "True"
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... | 1,184 | Python | .py | 35 | 30.285714 | 89 | 0.682582 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,702 | dataset.py | dajuric_dark/dark-5/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,703 | eval.py | dajuric_dark/dark-5/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,704 | eval.py | dajuric_dark/dark-5/samples/1.0-Func-derivation/dark/eval.py | import os
os.environ["USE_CPU"] = "True"
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(da... | 743 | Python | .py | 22 | 29.954545 | 100 | 0.618513 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,705 | util.py | dajuric_dark/dark-5/samples/5.0-ResNet-classification/torch/util.py | import numpy as np
import cv2
import torch
from config import *
def _draw_label(im, correct, label):
color = (0, 255, 0) if correct == 1 else (0, 0, 255)
cv2.putText(im, label, (5, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
def save_samples(dataset, model, str_labels, filename, grid = (3, 5)):
h, w = g... | 1,175 | Python | .py | 28 | 32.535714 | 76 | 0.585077 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,706 | config.py | dajuric_dark/dark-5/samples/5.0-ResNet-classification/torch/config.py | import os
import torch
IM_SIZE = 32
BATCH_SIZE = 128
CLASS_COUNT = 2 # 10 for full dataset
EPOCHS = 5
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print(f"Running on: {device}")
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f"{script_dir}/model.pickle" | 291 | Python | .py | 10 | 27.8 | 56 | 0.730216 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,707 | train.py | dajuric_dark/dark-5/samples/5.0-ResNet-classification/torch/train.py | import os
import torch
import torch.nn as nn
from torch.optim import *
from rich.progress import track
from model import Resnet9, get_net
from dataset import get_loaders
from config import *
from util import save_samples
def train_loop(dataloader, model, loss_fn, optimizer):
model.train()
size = len(dataloader... | 2,294 | Python | .py | 59 | 32.491525 | 126 | 0.610231 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,708 | dataset.py | dajuric_dark/dark-5/samples/5.0-ResNet-classification/torch/dataset.py | from torch.utils.data import DataLoader
from torchvision.datasets import ImageFolder
from torchvision.transforms import *
from config import *
def get_loaders():
def label_transform(l):
one_hot = torch.zeros(CLASS_COUNT, dtype=torch.float32)
one_hot[l] = 1
return one_hot
trTransforms =... | 858 | Python | .py | 25 | 28.32 | 84 | 0.667874 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,709 | model.py | dajuric_dark/dark-5/samples/5.0-ResNet-classification/torch/model.py | import torch
import torch.nn as nn
import os
from config import *
class ConvBlock(nn.Module):
def __init__(self, in_channels, out_channels, pool_no=-1):
super().__init__()
list = [
nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1),
nn.BatchNorm2d(out_channels)... | 1,766 | Python | .py | 50 | 26.3 | 76 | 0.574275 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,710 | util.py | dajuric_dark/dark-5/samples/5.0-ResNet-classification/dark/util.py | import numpy as np
import cv2
import dark.tensor as dt
def _draw_label(im, correct, label):
color = (0, 255, 0) if correct == 1 else (0, 0, 255)
cv2.putText(im, label, (5, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
def save_samples(dataset, model, str_labels, filename, grid = (3, 5)):
h, w = grid
i... | 1,113 | Python | .py | 26 | 33.230769 | 76 | 0.588462 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,711 | config.py | dajuric_dark/dark-5/samples/5.0-ResNet-classification/dark/config.py | import os
import dark.tensor as dt
IM_SIZE = 32
BATCH_SIZE = 128
CLASS_COUNT = 2 # 10 for full dataset
EPOCHS = 5
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" | 272 | Python | .py | 9 | 29.111111 | 57 | 0.717557 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,712 | train.py | dajuric_dark/dark-5/samples/5.0-ResNet-classification/dark/train.py | import dark
import dark.nn as nn
from dark.optim import *
import dark.tensor as dt
from rich.progress import track
from model import Resnet9, get_net
from dataset import get_loaders
from config import *
from util import save_samples
def train_loop(dataloader, model, loss_fn, optimizer):
model.train()
size = le... | 2,214 | Python | .py | 56 | 33.071429 | 107 | 0.615747 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,713 | dataset.py | dajuric_dark/dark-5/samples/5.0-ResNet-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 = dt.zeros(CLASS_COUNT, dtype=dt.float64)
one_hot[l] = 1
return one_hot
trTransforms = Compose(
Resize(IM_SIZE, IM_SIZ... | 830 | Python | .py | 24 | 28.375 | 84 | 0.655431 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,714 | model.py | dajuric_dark/dark-5/samples/5.0-ResNet-classification/dark/model.py | import dark
import dark.nn as nn
import dark.tensor as dt
from dark.nn.init import default_init_weights
from config import *
class ConvBlock(nn.Module):
def __init__(self, in_channels, out_channels, pool_no=-1):
super().__init__()
list = [
nn.Conv2d(in_channels, out_channels, kernel_si... | 1,860 | Python | .py | 51 | 27.509804 | 76 | 0.58864 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,715 | util.py | dajuric_dark/dark-5/samples/4.0-NN-classification/torch/util.py | import numpy as np
import cv2
import torch
from config import *
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 r... | 1,075 | Python | .py | 28 | 29.357143 | 72 | 0.568317 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,716 | config.py | dajuric_dark/dark-5/samples/4.0-NN-classification/torch/config.py | import os
import torch
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print(f"Running on: {device}")
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f"{script_dir}/model.pth"
IM_SIZE = 28
BATCH_SIZE = 32
CLASS_COUNT = 10
EPOCHS = 5 | 265 | Python | .py | 10 | 25.3 | 56 | 0.727273 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,717 | test.py | dajuric_dark/dark-5/samples/4.0-NN-classification/torch/test.py | import numpy as np
import cv2
import glob
import matplotlib.pyplot as plt
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)
im = cv... | 877 | Python | .py | 33 | 22.69697 | 59 | 0.640382 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,718 | train.py | dajuric_dark/dark-5/samples/4.0-NN-classification/torch/train.py | import numpy as np
import torch.nn as nn
from torch.optim 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, loss_fn, optimizer):
model.train()
size = len(dataloader.datase... | 2,256 | Python | .py | 58 | 32.396552 | 86 | 0.605166 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,719 | dataset.py | dajuric_dark/dark-5/samples/4.0-NN-classification/torch/dataset.py |
from torch.utils.data import DataLoader
from torchvision.datasets import ImageFolder
from torchvision.transforms import *
from config import *
def get_loaders():
def label_transform(l):
one_hot = torch.zeros(CLASS_COUNT, dtype=torch.float32)
one_hot[l] = 1
return one_hot
trTransforms... | 924 | Python | .py | 27 | 27.925926 | 84 | 0.655056 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,720 | model.py | dajuric_dark/dark-5/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,721 | util.py | dajuric_dark/dark-5/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,722 | config.py | dajuric_dark/dark-5/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,723 | test.py | dajuric_dark/dark-5/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,724 | train.py | dajuric_dark/dark-5/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,725 | dataset.py | dajuric_dark/dark-5/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,726 | model.py | dajuric_dark/dark-5/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,727 | util.py | dajuric_dark/dark-5/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,728 | train.py | dajuric_dark/dark-5/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,729 | dataset.py | dajuric_dark/dark-5/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,730 | model.py | dajuric_dark/dark-5/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,731 | util.py | dajuric_dark/dark-5/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,732 | train.py | dajuric_dark/dark-5/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,733 | dataset.py | dajuric_dark/dark-5/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,734 | model.py | dajuric_dark/dark-5/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,735 | process_db.py | dajuric_dark/dark-5/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,736 | util.py | dajuric_dark/dark-5/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,737 | config.py | dajuric_dark/dark-5/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,738 | test_camera.py | dajuric_dark/dark-5/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,739 | train.py | dajuric_dark/dark-5/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,740 | dataset.py | dajuric_dark/dark-5/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,741 | model.py | dajuric_dark/dark-5/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,742 | util.py | dajuric_dark/dark-5/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,743 | config.py | dajuric_dark/dark-5/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,744 | test_camera.py | dajuric_dark/dark-5/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,745 | train.py | dajuric_dark/dark-5/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,746 | dataset.py | dajuric_dark/dark-5/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,747 | model.py | dajuric_dark/dark-5/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,748 | util.py | dajuric_dark/dark-5/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,749 | train.py | dajuric_dark/dark-5/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,750 | util.py | dajuric_dark/dark-5/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,751 | train.py | dajuric_dark/dark-5/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,752 | test_conv2d.py | dajuric_dark/dark-5/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,753 | testConv2d.py | dajuric_dark/dark-5/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,754 | testMaxPool2d.py | dajuric_dark/dark-5/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,755 | __init__.py | dajuric_dark/dark-5/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,756 | optimizers.py | dajuric_dark/dark-5/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,757 | transforms.py | dajuric_dark/dark-5/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,758 | util.py | dajuric_dark/dark-5/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,759 | point_transforms.py | dajuric_dark/dark-5/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,760 | serialization.py | dajuric_dark/dark-5/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,761 | data.py | dajuric_dark/dark-5/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,762 | ops.py | dajuric_dark/dark-5/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,763 | pool.py | dajuric_dark/dark-5/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,764 | conv.py | dajuric_dark/dark-5/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,765 | util.py | dajuric_dark/dark-5/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,766 | pool.py | dajuric_dark/dark-5/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,767 | conv.py | dajuric_dark/dark-5/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,768 | autodiff.py | dajuric_dark/dark-5/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,769 | utils.py | dajuric_dark/dark-5/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,770 | operations.py | dajuric_dark/dark-5/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... | 8,069 | Python | .py | 231 | 28.151515 | 105 | 0.61298 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,771 | module.py | dajuric_dark/dark-5/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,772 | init.py | dajuric_dark/dark-5/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,068 | Python | .py | 30 | 30.133333 | 60 | 0.623047 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,773 | __init__.py | dajuric_dark/dark-5/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,774 | losses.py | dajuric_dark/dark-5/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,775 | modules.py | dajuric_dark/dark-5/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... | 4,280 | Python | .py | 105 | 32.847619 | 147 | 0.601854 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,776 | setup.py | dajuric_dark/dark-6/setup.py | from setuptools import setup
setup(
name="dark",
description="",
version="6.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,777 | util.py | dajuric_dark/dark-6/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,778 | train.py | dajuric_dark/dark-6/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,779 | dataset.py | dajuric_dark/dark-6/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,780 | util.py | dajuric_dark/dark-6/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,781 | train.py | dajuric_dark/dark-6/samples/2.0-Func-logistic-regression/dark/train.py | import os
os.environ["USE_CPU"] = "True"
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... | 1,184 | Python | .py | 35 | 30.285714 | 89 | 0.682582 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,782 | dataset.py | dajuric_dark/dark-6/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,783 | eval.py | dajuric_dark/dark-6/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,784 | eval.py | dajuric_dark/dark-6/samples/1.0-Func-derivation/dark/eval.py | import os
os.environ["USE_CPU"] = "True"
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(da... | 743 | Python | .py | 22 | 29.954545 | 100 | 0.618513 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,785 | util.py | dajuric_dark/dark-6/samples/5.0-ResNet-classification/torch/util.py | import numpy as np
import cv2
import torch
from config import *
def _draw_label(im, correct, label):
color = (0, 255, 0) if correct == 1 else (0, 0, 255)
cv2.putText(im, label, (5, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
def save_samples(dataset, model, str_labels, filename, grid = (3, 5)):
h, w = g... | 1,175 | Python | .py | 28 | 32.535714 | 76 | 0.585077 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,786 | config.py | dajuric_dark/dark-6/samples/5.0-ResNet-classification/torch/config.py | import os
import torch
IM_SIZE = 32
BATCH_SIZE = 128
CLASS_COUNT = 2 # 10 for full dataset
EPOCHS = 5
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print(f"Running on: {device}")
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f"{script_dir}/model.pickle" | 291 | Python | .py | 10 | 27.8 | 56 | 0.730216 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,787 | train.py | dajuric_dark/dark-6/samples/5.0-ResNet-classification/torch/train.py | import os
import torch
import torch.nn as nn
from torch.optim import *
from rich.progress import track
from model import Resnet9, get_net
from dataset import get_loaders
from config import *
from util import save_samples
def train_loop(dataloader, model, loss_fn, optimizer):
model.train()
size = len(dataloader... | 2,294 | Python | .py | 59 | 32.491525 | 126 | 0.610231 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,788 | dataset.py | dajuric_dark/dark-6/samples/5.0-ResNet-classification/torch/dataset.py | from torch.utils.data import DataLoader
from torchvision.datasets import ImageFolder
from torchvision.transforms import *
from config import *
def get_loaders():
def label_transform(l):
one_hot = torch.zeros(CLASS_COUNT, dtype=torch.float32)
one_hot[l] = 1
return one_hot
trTransforms =... | 858 | Python | .py | 25 | 28.32 | 84 | 0.667874 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,789 | model.py | dajuric_dark/dark-6/samples/5.0-ResNet-classification/torch/model.py | import torch
import torch.nn as nn
import os
from config import *
class ConvBlock(nn.Module):
def __init__(self, in_channels, out_channels, pool_no=-1):
super().__init__()
list = [
nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1),
nn.BatchNorm2d(out_channels)... | 1,766 | Python | .py | 50 | 26.3 | 76 | 0.574275 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,790 | util.py | dajuric_dark/dark-6/samples/5.0-ResNet-classification/dark/util.py | import numpy as np
import cv2
import dark.tensor as dt
def _draw_label(im, correct, label):
color = (0, 255, 0) if correct == 1 else (0, 0, 255)
cv2.putText(im, label, (5, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
def save_samples(dataset, model, str_labels, filename, grid = (3, 5)):
h, w = grid
i... | 1,113 | Python | .py | 26 | 33.230769 | 76 | 0.588462 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,791 | config.py | dajuric_dark/dark-6/samples/5.0-ResNet-classification/dark/config.py | import os
import dark.tensor as dt
IM_SIZE = 32
BATCH_SIZE = 128
CLASS_COUNT = 2 # 10 for full dataset
EPOCHS = 5
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" | 272 | Python | .py | 9 | 29.111111 | 57 | 0.717557 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,792 | train.py | dajuric_dark/dark-6/samples/5.0-ResNet-classification/dark/train.py | import dark
import dark.nn as nn
from dark.optim import *
import dark.tensor as dt
from rich.progress import track
from model import Resnet9, get_net
from dataset import get_loaders
from config import *
from util import save_samples
def train_loop(dataloader, model, loss_fn, optimizer):
model.train()
size = le... | 2,214 | Python | .py | 56 | 33.071429 | 107 | 0.615747 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,793 | dataset.py | dajuric_dark/dark-6/samples/5.0-ResNet-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 = dt.zeros(CLASS_COUNT, dtype=dt.float64)
one_hot[l] = 1
return one_hot
trTransforms = Compose(
Resize(IM_SIZE, IM_SIZ... | 830 | Python | .py | 24 | 28.375 | 84 | 0.655431 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,794 | model.py | dajuric_dark/dark-6/samples/5.0-ResNet-classification/dark/model.py | import dark
import dark.nn as nn
import dark.tensor as dt
from dark.nn.init import default_init_weights
from config import *
class ConvBlock(nn.Module):
def __init__(self, in_channels, out_channels, pool_no=-1):
super().__init__()
list = [
nn.Conv2d(in_channels, out_channels, kernel_si... | 1,860 | Python | .py | 51 | 27.509804 | 76 | 0.58864 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,795 | util.py | dajuric_dark/dark-6/samples/4.0-NN-classification/torch/util.py | import numpy as np
import cv2
import torch
from config import *
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 r... | 1,075 | Python | .py | 28 | 29.357143 | 72 | 0.568317 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,796 | config.py | dajuric_dark/dark-6/samples/4.0-NN-classification/torch/config.py | import os
import torch
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print(f"Running on: {device}")
script_dir = os.path.dirname(os.path.realpath(__file__))
model_path = f"{script_dir}/model.pth"
IM_SIZE = 28
BATCH_SIZE = 32
CLASS_COUNT = 10
EPOCHS = 5 | 265 | Python | .py | 10 | 25.3 | 56 | 0.727273 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,797 | test.py | dajuric_dark/dark-6/samples/4.0-NN-classification/torch/test.py | import numpy as np
import cv2
import glob
import matplotlib.pyplot as plt
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)
im = cv... | 877 | Python | .py | 33 | 22.69697 | 59 | 0.640382 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,798 | train.py | dajuric_dark/dark-6/samples/4.0-NN-classification/torch/train.py | import numpy as np
import torch.nn as nn
from torch.optim 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, loss_fn, optimizer):
model.train()
size = len(dataloader.datase... | 2,256 | Python | .py | 58 | 32.396552 | 86 | 0.605166 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,284,799 | dataset.py | dajuric_dark/dark-6/samples/4.0-NN-classification/torch/dataset.py |
from torch.utils.data import DataLoader
from torchvision.datasets import ImageFolder
from torchvision.transforms import *
from config import *
def get_loaders():
def label_transform(l):
one_hot = torch.zeros(CLASS_COUNT, dtype=torch.float32)
one_hot[l] = 1
return one_hot
trTransforms... | 924 | Python | .py | 27 | 27.925926 | 84 | 0.655056 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |