Skip to content

Instantly share code, notes, and snippets.

View mstevenson's full-sized avatar

Michael Stevenson mstevenson

View GitHub Profile
@mstevenson
mstevenson / RemapAssetRefs.py
Created February 27, 2025 03:15
Regenerate Unity asset GUIDs while preserving local asset references. Useful for duplicating an entire directory of inter-dependent assets.
import os
import sys
import argparse
import uuid
import logging
from concurrent.futures import ThreadPoolExecutor
from typing import List, Tuple, Dict, Optional
logging.basicConfig(level=logging.INFO, format='%(message)s')
@mstevenson
mstevenson / migrate.sh
Created February 23, 2025 22:24
Migrate Unity binary assets to Git LFS
git lfs migrate import --include="*.unitypackage,*.cubemap,*.ma,*.mb,*.obj,*.fbx,*.ztl,*.zbr,*.max,*.stl,*.blend,*.lxo,*.dae,*.jpg,*.jpeg,*.png,*.gif,*.tif,*.tiff,*.bmp,*.exr,*.hdr,*.psd,*.tga,*.pdf,*.ai,*.webp,*.zip,*.gz,*.7z,*.rar,*.tar,*.mov,*.avi,*.mp4,*.m4v,*.mpg,*.mpeg,*.ogv,*.ogx,*.webm,*.mp4,*.m4a,*.ogg,*.oga,*.spx,*.aif,*.aiff,*.wav,*.flac,*.bank,*.dll,*.so,*.exe,*.dat" --everything
@mstevenson
mstevenson / ia_image_downloader.py
Last active November 25, 2022 00:47
Download all images from an Internet Archive collection and write the caption to a text file
import internetarchive as ia
from pathlib import Path
import argparse
import time
config = dict(general=dict(secure=False))
def download_collection(collection_name, output_dir):
search = ia.search_items(f'collection:{collection_name}', config=config)
dir = Path(output_dir) / collection_name
@mstevenson
mstevenson / extract_video_frames.py
Created November 14, 2022 21:11
Extract frames every n seconds from a directory of videos
# extract frames every n seconds from a directory of videos
import cv2
import os
from pathlib import Path
video_base_path = Path('videos')
frames_root_path = Path('frames')
interval = 30 #seconds
@mstevenson
mstevenson / image_caption_gui.py
Last active October 18, 2024 08:40
Manual image captioning tool for Stable Diffusion training
# Python GUI tool to manually caption images for machine learning.
# A sidecar file is created for each image with the same name and a .txt extension.
#
# [control/command + o] to open a folder of images.
# [page down] and [page up] to go to next and previous images. Hold shift to skip 10 images.
# [shift + home] and [shift + end] to go to first and last images.
# [shift + delete] to move the current image into a '_deleted' folder.
# [escape] to exit the app.
import os
@mstevenson
mstevenson / sd_crop.py
Created November 8, 2022 05:30
Stable Diffusion training image cropping utility
import os
from PIL import Image
path = 'input_image_dir_path'
save_path = 'output_image_dir_path'
for filename in os.listdir(path):
img = Image.open(path + filename)
if img is not None:
width, height = img.size
@mstevenson
mstevenson / sd_crop.js
Created October 14, 2022 23:28
Photoshop script to crop and resize images for Stable Diffusion training
#target photoshop
// open a folder of images
var folder = Folder.selectDialog("Select a folder of JPGs to crop");
var files = folder.getFiles("*.jpg");
// create a folder to save the files to if it doesn't exist
var saveFolder = new Folder(folder + "/cropped");
if (!saveFolder.exists) saveFolder.create();
@mstevenson
mstevenson / fix-synalize-it.md
Created August 10, 2022 15:37 — forked from dreness/fix-synalize-it.md
A somewhat brutal repair of Synalize It! Pro for macOS, which is broken by linking against the system-provided python which no longer exists.

check current python linkage

% otool -L /Applications/Synalyze\ It\!\ Pro.app/Contents/MacOS/Synalyze\ It\!\ Pro | grep Python
	/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.16)

Download and install Python2.7.16 for macOS. By default this lands in /Library/Frameworks/Python.framework/Versions/2.7

Make a copy of the Synalize It! Pro app bundle, e.g. to your desktop.

cp -R /Applications/Synalyze\ It\!\ Pro.app ~/Desktop
@mstevenson
mstevenson / mov_to_mp4.sh
Last active July 18, 2022 19:34
Shell script to batch convert old QuickTime moves to MP4
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
OUTPUT="$SCRIPT_DIR/output"
if [ ! -d "$OUTPUT" ]; then
mkdir -p "$OUTPUT";
fi
for i in *.mov;
@mstevenson
mstevenson / .gitattributes
Last active March 6, 2023 16:31
Git configuration files for Unity projects
*.cs diff=csharp
# Macro attribute, linguist-generated means the file is ignored for the
# repository's language statistics and diffs are hidden by default
[attr]unity-yaml-file -text -merge=unityamlmerge linguist-generated
# Macro attribute for LFS files
[attr]lfs-file filter=lfs diff=lfs merge=lfs -text
### Unity YAML Files ###