Skip to content

Instantly share code, notes, and snippets.

View shrimo's full-sized avatar

Shri Moo shrimo

View GitHub Profile
@shrimo
shrimo / digital_life_nn.py
Last active April 19, 2025 21:19
Digital life
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
@shrimo
shrimo / simple_transformer.py
Created March 2, 2025 00:05
SimpleTransformer
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)]
@shrimo
shrimo / transformer_chatbot.py
Created March 1, 2025 23:37
TransformerChatbot
import torch
import torch.nn as nn
import torch.optim as optim
import os
# Tokenization
def tokenize(sentence):
return sentence.lower().split()
# Vocabulary
@shrimo
shrimo / shebang.py
Created February 1, 2025 00:19
Shebang Line
#!/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.
"""
@shrimo
shrimo / feature_points.py
Created March 8, 2024 00:24
Feature points (CV)
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]))
@shrimo
shrimo / GPTDescriptor.py
Last active October 10, 2023 11:42
an attempt to speed up the calculation of the descriptor when communicating with ChatGPT
#!/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)
@shrimo
shrimo / mp_tiled_frame.py
Last active August 1, 2023 18:30
Dividing the frame into tiles
#!/usr/bin/python3
# Dividing the frame into tiles
import multiprocessing
import numpy as np
import cv2
class OpenCV_Multiprocessing:
def __init__(self, features):
@shrimo
shrimo / ReduceDraw.py
Last active August 8, 2023 23:32
Draw no loops in OpenCV
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
@shrimo
shrimo / fft.py
Last active March 26, 2023 22:55
FourierTransform
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)
@shrimo
shrimo / strange.py
Created March 4, 2023 18:28
strange object behavior
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)))