Skip to content

Instantly share code, notes, and snippets.

@secemp9
secemp9 / vlm_token_vis_moondream.py
Created May 31, 2025 20:53
attempt at reproducing https://www.groundlight.ai/blog/how-vlm-works-tokens 's interactive vlm demo to visualize tokens on their patch/predicted region on an image
import torch, torch.nn.functional as F
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoProcessor
from PIL import Image
REVISION = "2025-04-14" # lock to a known good tag
MODEL_ID = "vikhyatk/moondream2"
device = "cuda" # or "cpu" / bitsandbytes / GGUF, etc.
# 1๏ธโƒฃ load model + text tokenizer
model = AutoModelForCausalLM.from_pretrained(
@secemp9
secemp9 / vlm_token_vis_llava.py
Created May 31, 2025 20:52
attempt at reproducing https://www.groundlight.ai/blog/how-vlm-works-tokens 's interactive vlm demo to visualize tokens on their patch/predicted region on an image
import torch, torch.nn.functional as F
from transformers import AutoProcessor, LlavaForConditionalGeneration
from PIL import Image
MODEL_ID = "llava-hf/llava-1.5-7b-hf"
device = "cuda"
model = LlavaForConditionalGeneration.from_pretrained(
MODEL_ID, torch_dtype=torch.float16, device_map="auto")
processor = AutoProcessor.from_pretrained(MODEL_ID)
@secemp9
secemp9 / rotation_invariant_cnn.py
Created May 31, 2025 04:21
rotation invariant CNN implementation
# -*- coding: utf-8 -*-
"""
CyCNN implementation for rotation invariant image classification.
Based on "CyCNN: A Rotation Invariant CNN using Polar Mapping and Cylindrical Convolution Layers"
"""
# Core Libraries
import os
import random
import time
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chips Filter Demo</title>
<style>
body {
@secemp9
secemp9 / autocolor_ps.py
Created May 6, 2025 23:54
autocolor (photoshop) inspired algorithm
def improved_auto_color(image: Image.Image) -> Image.Image:
"""
Improved version of Photoshop-like Auto Color.
It works by:
1. Converting to float and normalizing.
2. Computing per-channel percentiles (e.g., 0.5% and 99.5%).
3. Stretching values between those percentiles to [0, 255].
4. This avoids over-amplifying noise or outliers.
"""
img_array = np.array(image).astype(np.float32)
#!/usr/bin/env python3
import sys
import os
from google import genai
from google.genai import types
from PIL import Image
import readline # For command history
def print_usage():
"""Print usage instructions."""
import json
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from collections import Counter
from datetime import datetime, timedelta
import seaborn as sns
import matplotlib.dates as mdates
from matplotlib.gridspec import GridSpec
import re
import random
# Generate random byte data
N = 8 # Number of chunks
byte_data = bytes(random.getrandbits(8) for _ in range(1024)) # Generate 1024 random bytes
# Split into N equal chunks using plain Python
chunk_size = len(byte_data) // N
split_data = [byte_data[i * chunk_size : (i + 1) * chunk_size] for i in range(N)]

Got it! I'll find the best resources to get you up to speed on Monte Carlo Tree Search (MCTS) without reinventing the wheel. This will include:

  • The most cited and accessible foundational papers.
  • High-quality GitHub repositories with clear implementations.
  • Tutorials or blog posts that explain MCTS concepts and provide code examples.

I'll get back to you shortly with the best materials!

Best Resources for Learning Monte Carlo Tree Search (MCTS)

Learning MCTS efficiently involves understanding the core algorithm and having practical examples to follow. Below are top resources grouped by foundational readings, tutorials, and code implementations, so you can quickly grasp MCTS concepts and apply them without reinventing the wheel.

@secemp9
secemp9 / step.md
Last active February 13, 2025 13:22
step to install darknet on 22.04
sudo apt-get update
sudo apt-get install -y build-essential git cuda-libraries-dev-12-8 libopencv-dev gpg wget
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null

echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ <distro> main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null

sudo apt-get update
sudo apt-get install gcc-12 g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12