Skip to content

Instantly share code, notes, and snippets.

View sachadee's full-sized avatar

SachaDee sachadee

View GitHub Profile
with torch.no_grad():
for idx, (image, _) in enumerate(
tqdm(loader, desc="Create embeddings matrix", total=len(loader)),
):
embeddings = np.empty([1,512])
embeddings[int(0) :] = F.normalize(backbone(image.to(device))).cpu()
image = image[0].permute(1,2,0)
imgarr = image.cpu().detach().numpy()
print(imgarr.dtype)
opencvImage = cv2.cvtColor(imgarr, cv2.COLOR_RGB2BGR)
@sachadee
sachadee / decrypt_AESGCM_from_python.js
Last active July 8, 2024 01:41
Decrypt AES-GCM from python in Javascript (128 bits)
//Function to get to convert to bytes the base64 values from python
function base64ToUint8Array(base64) {
var binaryString = atob(base64);
var len = binaryString.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes;
@sachadee
sachadee / encrypt_python_AES_GCM.py
Created July 7, 2024 23:54
Python code to crypt a message with AES-GCM 128 bits
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
import base64
def encrypt_aes_gcm(plaintext, key):
cipher = AES.new(key, AES.MODE_GCM)
ciphertext, tag = cipher.encrypt_and_digest(plaintext)
return ciphertext, cipher.nonce, tag
# Example usage
inflect
librosa==0.9.2
matplotlib
numpy
Pillow
PyQt5
scikit-learn
scipy
sounddevice
SoundFile==0.10.3.post1
@sachadee
sachadee / detectionclass.onnx
Last active May 10, 2025 17:21
ONNX PaddleOCR Detection Class
import math
import os
import cv2
import numpy as np
from pyclipper import *
from shapely.geometry import Polygon
class Detection:
def __init__(self, onnx_path, session=None):
@sachadee
sachadee / test.py
Last active May 10, 2025 17:57
ONNX PaddleOCR inference code
import os
import cv2
import numpy as np
from util import detectionclass as net
detection = net.Detection('./weights/detection.onnx')
def main():
frame = cv2.imread('./images/plate.jpg')
image = frame.copy()
@sachadee
sachadee / testOV.py
Created May 10, 2025 19:32
OpenVino PaddleOcr inference test
import os
import cv2
import numpy as np
from util import detectionclassOV as net
detection = net.Detection("./weights/compiled_detection.blob")
def main():
frame = cv2.imread('./images/plate.jpg')
image = frame.copy()
@sachadee
sachadee / clientDll.py
Last active September 6, 2026 23:32
io.BytesIO
import io
import base64
import requests
import onnxruntime as ort
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
SERVER_URL = "http://127.0.0.1:8000"
def decrypt_data(encryptedModel, decryptKey) -> bytes:
@sachadee
sachadee / gist:3624c2faef2008fd6b5a73e19e08d78a
Last active September 6, 2026 07:37
Fast API with FERNET
import sqlite3
import random
import os
import base64
import uuid
from typing import Tuple
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import io
from cryptography.hazmat.primitives import hashes
class PolynomialMultiKeyEncryption:
def __init__(self, raw_data: bytes = None):
self.prime = 2**127 - 1
if raw_data:
self.model_bytes = raw_data
self.secret_value = random.randint(1000, 9999)
self.coefficients = [self.secret_value] + [random.randint(1, self.prime-1) for _ in range(2)]
self.salt = os.urandom(16)
self.encryption_key = self._derive_encryption_key(self.secret_value)
self.encrypted_data = self._encrypt_data()