Skip to content

Instantly share code, notes, and snippets.

View chenghanc's full-sized avatar
🛵
Focusing

chenghanc

🛵
Focusing
View GitHub Profile
@chenghanc
chenghanc / subtitles_moviepy_tts.py
Created September 28, 2025 01:23
Burn in captions_tts.srt (TTS)
#!/usr/bin/env python3
from pathlib import Path
import asyncio, tempfile, shutil, os
from typing import List, Tuple
from moviepy.editor import (
VideoFileClip, TextClip, CompositeVideoClip,
AudioFileClip, CompositeAudioClip
)
import pysubs2
@chenghanc
chenghanc / subtitles_moviepy.py
Created September 28, 2025 01:21
Burn in captions_tts.srt
from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip
import pysubs2
FONT_PATH = "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc" # Linux
# FONT_PATH = "C:/Windows/Fonts/msjh.ttc" # Windows
# FONT_PATH = "/Library/Fonts/PingFang.ttc" # macOS
# FONT_PATH = "/System/Library/Fonts/STHeiti Light.ttc" # macOS
video = VideoFileClip("./2-1.mp4")
@chenghanc
chenghanc / align_from_prompt_file.py
Created September 28, 2025 01:18
Align prompt.txt and file.wav to generate captions_tts.srt
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import sys
import json
import argparse
from pathlib import Path
from typing import List, Tuple, Optional
@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]: