Skip to content

Instantly share code, notes, and snippets.

@FreeFly19
FreeFly19 / essential_mat_decomposition.py
Created February 6, 2025 17:51
essential_mat_decomposition
import numpy as np
import cv2
from scipy.spatial.transform import Rotation as R
if __name__ == '__main__':
# Generating a random point cloud within specified spatial limits
num_points = 100 # Reduced number of points for clarity
points_3d = np.random.rand(num_points, 3) # Random points in 3D
# Scale and shift points to fit within the specified range
points_3d[:, 0] = points_3d[:, 0] * 1000 - 500 # X: -500 to 500 mm
import argparse
import dataclasses
import json
import math
import threading
import time
from typing import List
import matplotlib
import matplotlib.animation as animation
@FreeFly19
FreeFly19 / serial_uart_esp32_proxy.c
Created May 12, 2024 00:26
ESP32 USB to UART proxy
void setup() {
Serial.begin(230400,SERIAL_8N1);
Serial1.begin(230400, SERIAL_8N1, 21, 22);
}
int n;
void loop() {
n = Serial1.available();
if (n != 0)
{
import json
from argparse import ArgumentParser
def convert(input_file, output_file):
with open(input_file, 'r') as fin:
data2 = json.load(fin)
features = data2['features']
with open(output_file, 'w') as fout:
@FreeFly19
FreeFly19 / mnist_cnn.py
Created July 27, 2023 16:13
MNIST PyTorch CNN with skip connections
import numpy as np
import torch
import torchvision
from torch.utils.data import DataLoader
from torchvision.transforms import ToTensor
train_dataset = torchvision.datasets.MNIST('data', train=True, transform=ToTensor(), download=True)
test_dataset = torchvision.datasets.MNIST('data', train=False, transform=ToTensor(), download=True)
batch_size = 16
@FreeFly19
FreeFly19 / sqrt_sgd_pytorch.py
Created July 21, 2023 16:16
Square root finder with SGD(momentum + decay) on pytorch
import torch
w = torch.tensor([5.], requires_grad=True)
lr = 0.6
w_mom_grad = 0
momentum_coef = 0.9
weight_decay = 0.001
for i in range(10):
@FreeFly19
FreeFly19 / logistic_regression.py
Last active July 21, 2023 16:17
Logistic Regression from scratch with PyTorch
import torch
x = torch.tensor([1.5,2.8,15.,19.5])
y = torch.tensor([0.,0.,1.,1.])
w = torch.tensor([-.3], requires_grad=True)
b = torch.tensor([0.1232154], requires_grad=True)
def model(x):
import time
import av
import tqdm
from av.video import VideoStream
desired_fps = 2
timestamp = int(time.time())
@FreeFly19
FreeFly19 / client.ovpn
Last active March 6, 2023 02:27
Port forwarding + ovpn
client
# put the line below to disable tunneling outcoming trafic
route-nopull
....