Created
September 24, 2022 09:29
-
-
Save kabachuha/dc10718cfea51cca2b674d60bb9d095d to your computer and use it in GitHub Desktop.
updated deforum numexpr args troubleshooting test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0:(1.5), 20:(3), 40:(15), 60:(0), 80:(-15), 100:(-3), 120:(0), 240(3), 260(-3), 300(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import numpy as np | |
import numexpr | |
import pandas as pd | |
import re | |
def get_inbetweens(key_frames, max_frames, integer=False, interp_method='Linear'): | |
import re | |
float_pattern = r'^(?=.)([+-]?([0-9]*)(\.([0-9]+))?)$' | |
key_frame_series = pd.Series([np.nan for a in range(max_frames)]) | |
for i in range(0, max_frames): | |
if i in key_frames: | |
value = key_frames[i] | |
value_is_number = re.match(float_pattern, value) | |
# if it's only a number, leave the rest for the default interpolation | |
if value_is_number: | |
t = i | |
key_frame_series[i] = value | |
if not value_is_number: | |
t = i | |
key_frame_series[i] = numexpr.evaluate(value) | |
key_frame_series = key_frame_series.astype(float) | |
if interp_method == 'Cubic' and len(key_frames.items()) <= 3: | |
interp_method = 'Quadratic' | |
if interp_method == 'Quadratic' and len(key_frames.items()) <= 2: | |
interp_method = 'Linear' | |
key_frame_series[0] = key_frame_series[key_frame_series.first_valid_index()] | |
key_frame_series[max_frames-1] = key_frame_series[key_frame_series.last_valid_index()] | |
key_frame_series = key_frame_series.interpolate(method=interp_method.lower(), limit_direction='both') | |
if integer: | |
return key_frame_series.astype(int) | |
return key_frame_series | |
def parse_key_frames(string, prompt_parser=None): | |
import re | |
pattern = r'((?P<frame>[0-9]+):[\s]*\((?P<param>[\S\s]*?)\)([,][\s]?|[\s]?$))' | |
frames = dict() | |
for match_object in re.finditer(pattern, string): | |
frame = int(match_object.groupdict()['frame']) | |
param = match_object.groupdict()['param'] | |
if prompt_parser: | |
frames[frame] = prompt_parser(param) | |
else: | |
frames[frame] = param | |
if frames == {} and len(string) != 0: | |
raise RuntimeError('Key Frame string not correctly formatted') | |
return frames | |
max_frames = 300 | |
with open('more.txt', 'r', encoding='utf-8') as f: | |
data = f.read() | |
print(data) | |
translation_x_series = get_inbetweens(parse_key_frames(data), max_frames) | |
print(translation_x_series) | |
translation_x_series.to_csv('kek.csv') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0:(1.0+sin(t**2)), 20:(3), 40:(1.0+sin(t**2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0:(1.0+0.04*sin(6.28*t/10)), 20:(3),40:(1.0+cos(t**2)), 60:(0), 80:(-15), 100:(-3), 120:(0), 240(3), 260(-3), 300(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment