Skip to content

Instantly share code, notes, and snippets.

@tin2tin
tin2tin / forward_of_sdxl_original_unet.py
Created January 12, 2024 21:42 — forked from kohya-ss/forward_of_sdxl_original_unet.py
SDXLで高解像度での構図の破綻を軽減する
def forward(self, x, timesteps=None, context=None, y=None, **kwargs):
# broadcast timesteps to batch dimension
timesteps = timesteps.expand(x.shape[0])
hs = []
t_emb = get_timestep_embedding(timesteps, self.model_channels) # , repeat_only=False)
t_emb = t_emb.to(x.dtype)
emb = self.time_embed(t_emb)
assert x.shape[0] == y.shape[0], f"batch size mismatch: {x.shape[0]} != {y.shape[0]}"
@tin2tin
tin2tin / gist:afabeff69f6ea7c1ece267d24721941a
Created January 3, 2024 00:44
Path to installed add-on
addon_prefs = bpy.context.preferences.addons[__package__].preferences
@tin2tin
tin2tin / __init__.py
Created November 17, 2023 12:16
find frame in video
import cv2
import numpy as np
def find_image_in_video(video_path, image_path):
# Load the video clip
cap = cv2.VideoCapture(video_path)
# Load the image template
template = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
@tin2tin
tin2tin / __init__.py
Created November 17, 2023 12:15
Find clapper board in video
import cv2
import numpy as np
def detect_clapperboard(frame, clapperboard_template):
# Convert the frame to grayscale
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Use template matching to find the clapperboard
result = cv2.matchTemplate(gray_frame, clapperboard_template, cv2.TM_CCOEFF_NORMED)
@tin2tin
tin2tin / __init__.py
Created October 29, 2023 17:17
Install modules
import sys
import subprocess
import os
import bpy
import pkgutil
# Get the path to the Python interpreter used by Blender
python_path = sys.executable
# Determine the script directory
@tin2tin
tin2tin / __init__.py
Last active October 31, 2023 08:22
Join strips operator
import bpy
def join(vse, current_strip, next_strip):
# Calculate the duration of the next strip
duration = next_strip.frame_final_end - next_strip.frame_final_start
# Remove the next strip from the VSE
vse.sequences.remove(next_strip)
@tin2tin
tin2tin / __init__.py
Last active October 27, 2023 22:41
Find audio offset
import bpy
import librosa
import numpy as np
from scipy import signal
def normalize_audio(audio):
max_amplitude = np.max(np.abs(audio))
if max_amplitude > 0:
audio /= max_amplitude
return audio
@tin2tin
tin2tin / __init__.py
Created October 24, 2023 09:52
Add files to uilist
bl_info = {
"name": "LoRA Browser",
"blender": (2, 80, 0),
"category": "Object",
}
import bpy
import os
# Custom property to store the list of files
@tin2tin
tin2tin / __init__.py
Created October 13, 2023 06:33
Copy source material to folder for Blender
import bpy
import shutil
import os
from bpy.types import Operator
class CopyStripsOperator(Operator):
bl_idname = "sequencer.copy_strips"
bl_label = "Copy Strips to Folder"
def execute(self, context):
@tin2tin
tin2tin / sort_keymap_alphabetic.py
Created October 2, 2023 07:07
Sort keymap alphabetic
keyconfig_version = (3, 5, 10)
keyconfig_data = \
[("3D View",
{"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
{"items":
[("view3d.cursor3d", {"type": 'RIGHTMOUSE', "value": 'PRESS', "shift": True}, None),
("transform.translate",
{"type": 'RIGHTMOUSE', "value": 'CLICK_DRAG', "shift": True},
{"properties":
[("cursor_transform", True),