This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import torch | |
import torch.nn as nn | |
import torch.optim as optim | |
import random | |
# --- PARAMETERS --- | |
GRID_SIZE = 64 | |
NUM_ORGANISMS = 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import random | |
class SimpleTransformer: | |
def __init__(self, d_model): | |
"""Initializes the transformer with a given embedding size (d_model).""" | |
self.d_model = d_model | |
self.W_q = [[random.uniform(-0.5, 0.5) for _ in range(d_model)] for _ in range(d_model)] | |
self.W_k = [[random.uniform(-0.5, 0.5) for _ in range(d_model)] for _ in range(d_model)] | |
self.W_v = [[random.uniform(-0.5, 0.5) for _ in range(d_model)] for _ in range(d_model)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn as nn | |
import torch.optim as optim | |
import os | |
# Tokenization | |
def tokenize(sentence): | |
return sentence.lower().split() | |
# Vocabulary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
""" | |
In computing, a shebang is the character sequence #!, | |
consisting of the characters number sign (also known as sharp or | |
hash) and exclamation mark (also known as bang), | |
at the beginning of a script. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
file = "image.jpg" | |
img = cv2.imread(file) | |
[ | |
cv2.circle(img, (np.int32(ppt)), 5, (0, 255, 0), 1) | |
for ppt in [ | |
(int(points.pt[0]), int(points.pt[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# read, akaze and show | |
import cv2 | |
import multiprocessing | |
# Function to read video frames | |
def read_video_stream(video_file, frame_queue): | |
cap = cv2.VideoCapture(video_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# Dividing the frame into tiles | |
import multiprocessing | |
import numpy as np | |
import cv2 | |
class OpenCV_Multiprocessing: | |
def __init__(self, features): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReduceDraw: | |
""" | |
Class for drawing many objects without loops | |
""" | |
__slots__ = ['frame_tmp','color', 'size', 'font'] | |
def __init__(self, color = (0, 0, 255), size = 10): | |
self.frame_tmp = None | |
self.color = color | |
self.size = size | |
self.font = cv2.FONT_HERSHEY_SIMPLEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
from matplotlib import pyplot as plt | |
img = cv2.imread('image_big.png') | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
rows, colss = img.shape | |
crow, ccol = rows//2 , colss//2 | |
print(crow, ccol) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CX:... | |
CX.m = lambda x : x | |
a = CX | |
CX.n = lambda y : y | |
b = CX | |
print(a is b) | |
print(id(a.n(a)) is id(b.m(b))) | |
print(id(a.n(a)) == id(b.m(b))) |
NewerOlder