Skip to content

Instantly share code, notes, and snippets.

View happyme531's full-sized avatar

快乐的我531 happyme531

View GitHub Profile
blueprint:
name: 万能联动控制 (支持传感器/开关)
description: >
当触发器 A 变为 "开" (on) 时,如果目标 B 当前是 "关" (off) 的,则开启 B。
随后当 A 变为 "关" (off) 时,自动关闭 B。
如果 A 开启时 B 已经是开启状态,则忽略本次联动。
domain: automation
input:
trigger_entity:
name: 触发实体 A
@happyme531
happyme531 / janus_ort.py
Last active February 2, 2025 16:10
Deepseek's Janus Pro 1B ONNX python inference (https://huggingface.co/onnx-community/Janus-Pro-1B-ONNX)
import numpy as np
import onnxruntime as ort
from tokenizers import Tokenizer
import cv2
import tqdm
model_path = "."
onnx_model_path = f"{model_path}/onnx"
tokenizer = Tokenizer.from_file(f"{model_path}/tokenizer.json")
# np.random.seed(0)
@happyme531
happyme531 / rknn_transformer_runner.py
Created December 22, 2024 19:40
Hacky workaround of >4GB RKNN2 models. Only works for RKNPU2 kernel drivers version >=0.9.6 .
gcc -shared -fPIC rknpu2_domain_interceptor.c -o libdomain_interceptor.so -ldl -lrt
LD_PRELOAD=./libdomain_interceptor.so python ./test_rknn_runner.py
@happyme531
happyme531 / cn_natlist.py
Created July 3, 2024 08:25
考虑中文数字的自然排序
import os
import re
import pypinyin
from functools import cmp_to_key
dic = {"零":0,"一":1,"二":2,"三":3,"四":4,"五":5,"六":6,"七":7,"八":8,"九":9,"十":10,"百":100,"千":1000,"万":10000,"亿":100000000,"兆":1000000000000}
def chi_num(text):
if len(text) == 0:
@happyme531
happyme531 / run_rknn.py
Created July 2, 2024 09:01
RKNN2 accelerated Stable diffusion 1.5 (U-net is broken, only generates gray image?)
#python3 ./run_rknn.py -i ./out --prompt "A 4K photo of an astronant riding a horse on the moon" -o ./out.png --num-inference-steps 25 --scheduler EulerAncestralDiscreteScheduler --guidance-scale 6
import argparse
import json
import time
from diffusers import StableDiffusionPipeline
from diffusers.pipelines.pipeline_utils import DiffusionPipeline
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.schedulers import (
DDIMScheduler,
@happyme531
happyme531 / build.py
Created February 14, 2024 16:09
MLC Stable Diffusion for RK3588's Mali GPU
import logging
from typing import Dict, List, Tuple
import os
import argparse
import pickle
import web_stable_diffusion.trace as trace
import web_stable_diffusion.utils as utils
from platform import system
@happyme531
happyme531 / 3588PerfView.cpp
Created September 15, 2023 07:21
RK3588 GPU/NPU/DDR Load&Frequency viewer
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
int main() {
// 处理GPU
std::ifstream gpu_load("/sys/class/devfreq/fb000000.gpu/load");
std::string gpu;
@happyme531
happyme531 / FPSCounter.cpp
Created September 6, 2023 06:48
Handy FPS or whatever counter class
// Author: hallo1, 2023-09-06
// Description: Simple FPS or whatever counter
#pragma once
#include <chrono>
#include <iostream>
#include <string>
class FPSCounter {
private:
@happyme531
happyme531 / example.py
Created March 4, 2023 09:05
llama interactive example
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the GNU General Public License version 3.
from typing import Tuple
import os
import sys
import torch
import fire
import time
import json