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,285,000 | util.py | dajuric_dark/dark-7/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,285,001 | train.py | dajuric_dark/dark-7/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,285,002 | util.py | dajuric_dark/dark-7/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,285,003 | train.py | dajuric_dark/dark-7/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,285,004 | test_conv2d.py | dajuric_dark/dark-7/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,285,005 | testConv2d.py | dajuric_dark/dark-7/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,285,006 | testConv2dtranspose.py | dajuric_dark/dark-7/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,285,007 | testUpsample2d.py | dajuric_dark/dark-7/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,285,008 | testCNN.py | dajuric_dark/dark-7/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,285,009 | test_conv2dtranspose.py | dajuric_dark/dark-7/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,285,010 | testMaxPool2d.py | dajuric_dark/dark-7/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,285,011 | __init__.py | dajuric_dark/dark-7/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,285,012 | optimizers.py | dajuric_dark/dark-7/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,285,013 | transforms.py | dajuric_dark/dark-7/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,285,014 | util.py | dajuric_dark/dark-7/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,285,015 | point_transforms.py | dajuric_dark/dark-7/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,285,016 | serialization.py | dajuric_dark/dark-7/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,285,017 | data.py | dajuric_dark/dark-7/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,285,018 | ops.py | dajuric_dark/dark-7/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,285,019 | pool.py | dajuric_dark/dark-7/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,285,020 | conv.py | dajuric_dark/dark-7/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,285,021 | util.py | dajuric_dark/dark-7/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,285,022 | pool.py | dajuric_dark/dark-7/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,285,023 | conv.py | dajuric_dark/dark-7/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,285,024 | autodiff.py | dajuric_dark/dark-7/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,285,025 | utils.py | dajuric_dark/dark-7/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,285,026 | operations.py | dajuric_dark/dark-7/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... | 11,310 | Python | .py | 301 | 30.192691 | 137 | 0.612207 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,027 | module.py | dajuric_dark/dark-7/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,285,028 | init.py | dajuric_dark/dark-7/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,285,029 | __init__.py | dajuric_dark/dark-7/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,285,030 | losses.py | dajuric_dark/dark-7/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,285,031 | modules.py | dajuric_dark/dark-7/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,285,032 | setup.py | dajuric_dark/dark-4/setup.py | from setuptools import setup
setup(
name="dark",
description="",
version="4.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,285,033 | util.py | dajuric_dark/dark-4/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,285,034 | train.py | dajuric_dark/dark-4/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,285,035 | dataset.py | dajuric_dark/dark-4/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,285,036 | util.py | dajuric_dark/dark-4/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,285,037 | train.py | dajuric_dark/dark-4/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,285,038 | dataset.py | dajuric_dark/dark-4/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,285,039 | eval.py | dajuric_dark/dark-4/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,285,040 | eval.py | dajuric_dark/dark-4/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,285,041 | util.py | dajuric_dark/dark-4/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,285,042 | config.py | dajuric_dark/dark-4/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,285,043 | test.py | dajuric_dark/dark-4/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,285,044 | train.py | dajuric_dark/dark-4/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,285,045 | dataset.py | dajuric_dark/dark-4/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,285,046 | model.py | dajuric_dark/dark-4/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,285,047 | util.py | dajuric_dark/dark-4/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,003 | Python | .py | 26 | 29.423077 | 72 | 0.569607 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,048 | config.py | dajuric_dark/dark-4/samples/4.0-NN-classification/dark/config.py | import os
import dark.tensor as dt
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 | 192 | Python | .py | 8 | 22.875 | 56 | 0.743169 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,049 | test.py | dajuric_dark/dark-4/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,285,050 | train.py | dajuric_dark/dark-4/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,285,051 | dataset.py | dajuric_dark/dark-4/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,285,052 | model.py | dajuric_dark/dark-4/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,285,053 | util.py | dajuric_dark/dark-4/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,285,054 | train.py | dajuric_dark/dark-4/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,285,055 | dataset.py | dajuric_dark/dark-4/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,285,056 | model.py | dajuric_dark/dark-4/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,285,057 | util.py | dajuric_dark/dark-4/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,285,058 | train.py | dajuric_dark/dark-4/samples/3.0-Func-NN-regression/dark/train.py | 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.train()
loss_fn = nn.MSELoss()
opt = optim.... | 594 | Python | .py | 24 | 21.916667 | 46 | 0.694097 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,059 | dataset.py | dajuric_dark/dark-4/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,285,060 | model.py | dajuric_dark/dark-4/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,285,061 | util.py | dajuric_dark/dark-4/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,285,062 | train.py | dajuric_dark/dark-4/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,285,063 | util.py | dajuric_dark/dark-4/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,285,064 | train.py | dajuric_dark/dark-4/samples/1.1-Func-optimization/dark/train.py | 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 gradient
plot(lambda x: eval_func(x).dat... | 445 | Python | .py | 14 | 27.142857 | 61 | 0.609524 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,065 | __init__.py | dajuric_dark/dark-4/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,285,066 | optimizers.py | dajuric_dark/dark-4/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,285,067 | transforms.py | dajuric_dark/dark-4/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,285,068 | util.py | dajuric_dark/dark-4/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,285,069 | serialization.py | dajuric_dark/dark-4/dark/utils/serialization.py | import os
import pickle
def load(filename):
obj = pickle.load(open(filename, "rb"))
return obj
def save(obj, filename):
dirname = os.path.dirname(filename)
os.makedirs(dirname, exist_ok=True)
pickle.dump(obj, open(filename, "wb")) | 252 | Python | .py | 9 | 24.666667 | 43 | 0.710744 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,070 | data.py | dajuric_dark/dark-4/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,285,071 | ops.py | dajuric_dark/dark-4/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,285,072 | autodiff.py | dajuric_dark/dark-4/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,285,073 | utils.py | dajuric_dark/dark-4/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,285,074 | operations.py | dajuric_dark/dark-4/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) |
2,285,075 | module.py | dajuric_dark/dark-4/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,285,076 | init.py | dajuric_dark/dark-4/dark/nn/init.py | import dark.tensor as dt
import dark.nn as nn
from dark import *
def random_uniform_(tensor, a, b):
t_shape = tensor.data.shape
tensor.data = (b - a) * dt.random.rand(*t_shape) + a
def default_init_weights(m):
if isinstance(m, nn.Linear):
stdv = 1. / dt.sqrt(m.weights.data.shape[1])
rando... | 399 | Python | .py | 11 | 31.818182 | 56 | 0.65544 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,077 | __init__.py | dajuric_dark/dark-4/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,285,078 | losses.py | dajuric_dark/dark-4/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,285,079 | modules.py | dajuric_dark/dark-4/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... | 1,815 | Python | .py | 54 | 26.851852 | 147 | 0.601495 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,080 | setup.py | dajuric_dark/dark-3/setup.py | from setuptools import setup
setup(
name="dark",
description="",
version="3.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,285,081 | util.py | dajuric_dark/dark-3/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,285,082 | train.py | dajuric_dark/dark-3/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,285,083 | dataset.py | dajuric_dark/dark-3/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,285,084 | util.py | dajuric_dark/dark-3/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,285,085 | train.py | dajuric_dark/dark-3/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,285,086 | dataset.py | dajuric_dark/dark-3/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,285,087 | eval.py | dajuric_dark/dark-3/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,285,088 | eval.py | dajuric_dark/dark-3/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,285,089 | util.py | dajuric_dark/dark-3/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,285,090 | train.py | dajuric_dark/dark-3/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,285,091 | dataset.py | dajuric_dark/dark-3/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,285,092 | model.py | dajuric_dark/dark-3/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,285,093 | util.py | dajuric_dark/dark-3/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... | 580 | Python | .py | 18 | 26.222222 | 70 | 0.61597 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,094 | train.py | dajuric_dark/dark-3/samples/3.0-Func-NN-regression/dark/train.py | 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.train()
loss_fn = nn.MSELoss()
opt = optim.... | 594 | Python | .py | 24 | 21.916667 | 46 | 0.694097 | dajuric/dark | 8 | 0 | 0 | GPL-3.0 | 9/5/2024, 10:47:43 PM (Europe/Amsterdam) |
2,285,095 | dataset.py | dajuric_dark/dark-3/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,285,096 | model.py | dajuric_dark/dark-3/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,285,097 | util.py | dajuric_dark/dark-3/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,285,098 | train.py | dajuric_dark/dark-3/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,285,099 | util.py | dajuric_dark/dark-3/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) |