Skip to content

Instantly share code, notes, and snippets.

View chenghanc's full-sized avatar
🛵
Focusing

chenghanc

🛵
Focusing
View GitHub Profile
@chenghanc
chenghanc / cogvideox_2b_ch.py
Created August 11, 2025 09:37
CogVideoX-2b (LOW-VRAM build for 16GB GPUs (e.g. 4060Ti 16G) 中文
#!/usr/bin/env python3
"""
CogVideoX-2b Gradio demo — LOW-VRAM build for 16GB GPUs (e.g., 4060 Ti 16G)
UI updated for Chinese support, added a quick reset button for low-VRAM defaults.
"""
from __future__ import annotations
import argparse
import os
from pathlib import Path
@chenghanc
chenghanc / cogvideox_2b.py
Last active August 11, 2025 07:13
CogVideoX-2b (LOW-VRAM build for 16GB GPUs (e.g. 4060Ti 16G)
#!/usr/bin/env python3
"""
CogVideoX-2b Gradio demo — LOW-VRAM build for 16GB GPUs (e.g., 4060 Ti 16G)
Fix: added ndim existence checks to avoid AttributeError when output is None or unexpected.
"""
from __future__ import annotations
import argparse
import os
from pathlib import Path
@chenghanc
chenghanc / compute_mAP.py
Last active July 11, 2025 06:58
PR Curve
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
import argparse
import numpy as np
import matplotlib.pyplot as plt
def coco_eval(args):
cocoGt = COCO(args.gt_json)
cocoDt = cocoGt.loadRes(args.pred_json)
cocoEval = COCOeval(cocoGt, cocoDt, args.eval_type)
@chenghanc
chenghanc / Darknet53.py
Last active June 11, 2025 05:57
Darknet-53 in PyTorch
# https://github.com/developer0hye/PyTorch-Darknet53
import torch
from torch import nn
def conv_batch(in_num, out_num, kernel_size=3, padding=1, stride=1):
return nn.Sequential(
nn.Conv2d(in_num, out_num, kernel_size=kernel_size, stride=stride, padding=padding, bias=False),
nn.BatchNorm2d(out_num),
nn.LeakyReLU())
@chenghanc
chenghanc / ResNet50.py
Last active June 11, 2025 03:30
ResNet-50 in PyTorch
# https://blog.csdn.net/weixin_43397208/article/details/131352685
import torch
import torch.nn as nn
class IdentityBlock(nn.Module):
def __init__(self, in_channel, kl_size, filters):
super(IdentityBlock, self).__init__()
@chenghanc
chenghanc / sequential-numbers.txt
Created December 12, 2024 10:13
Renaming files in a folder to sequential numbers
# jpg files
a=1
for i in *.jpg; do
new=$(printf "%04d.jpg" "$a")
mv -i -- "$i" "$new"
let a="$a+1"
done
# xml files
a=1
@chenghanc
chenghanc / layers.txt
Created November 27, 2024 08:23 — forked from fabito/layers.txt
YOLO v3 Layers
layer filters size input output
0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 32
1 conv 64 3 x 3 / 2 416 x 416 x 32 -> 208 x 208 x 64
2 conv 32 1 x 1 / 1 208 x 208 x 64 -> 208 x 208 x 32
3 conv 64 3 x 3 / 1 208 x 208 x 32 -> 208 x 208 x 64
4 Shortcut Layer: 1
5 conv 128 3 x 3 / 2 208 x 208 x 64 -> 104 x 104 x 128
6 conv 64 1 x 1 / 1 104 x 104 x 128 -> 104 x 104 x 64
7 conv 128 3 x 3 / 1 104 x 104 x 64 -> 104 x 104 x 128
8 Shortcut Layer: 5
@chenghanc
chenghanc / comparebyNAME.py
Created November 19, 2024 03:21
Compare filenames with different extensions either jpg or txt. Delete the files of the form X.txt for which X.jpg does not exist in the directory and vice versa, X can be any.
# In[98]:
import os
from os.path import splitext
from collections import Counter
def compare(path):
# List containing all file names + their extension in path directory
myDir = os.listdir(path)
# List containing all file names without their extension
l = [splitext(filename)[0] for filename in myDir]
@chenghanc
chenghanc / coco-each-label.py
Last active November 4, 2024 14:26
Python script to generate 80-class folders and store the coco images and annotations for each class separately
# In[98]:
import pandas as pd
import os, glob
import sys
import shutil
import numpy as np
import cv2
# In[98]:
import os
import glob
import shutil
tp = 'TP'
fp = 'FP'
fn = 'FN'
model_name = 'yolo'