-
-
Save Tydus/987239fea966438d8a873fbb083240d6 to your computer and use it in GitHub Desktop.
import json, sys, numpy as np | |
from scipy import misc, signal | |
from PIL import Image | |
infile, outfile, modelpath = sys.argv[1:] | |
model = json.load(open(modelpath)) | |
im = Image.open(infile).convert("YCbCr") | |
im = misc.fromimage(im.resize((2*im.size[0], 2*im.size[1]), resample=Image.NEAREST)).astype("float32") | |
planes = [np.pad(im[:,:,0], len(model), "edge") / 255.0] | |
for step in model: | |
o_planes = [sum([signal.convolve2d(ip, np.float32(kernel), "valid") | |
for ip, kernel in zip(planes, weights)]) + np.float32(bias) | |
for bias, weights in zip(step["bias"], step["weight"])] | |
planes = [np.maximum(p, 0) + 0.1 * np.minimum(p, 0) for p in o_planes] | |
im[:,:,0] = np.clip(planes[0], 0, 1) * 255 | |
misc.toimage(im, mode="YCbCr").convert("RGB").save(outfile) |
@Tydus
error:
im[:,:,-1] = np.clip(planes[0], 0, 1) * 255
ValueError: could not broadcast input array from shape (51,43) into shape (52,44)
Note that my input image is 51x43
@NekoTony
in the main waifu repo
you can find models in models/photo/
It's mean ./upconv_7/photo. Is this your model?
@Tydus
error:
im[:,:,-1] = np.clip(planes[0], 0, 1) * 255
ValueError: could not broadcast input array from shape (51,43) into shape (52,44)
Note that my input image is 51x43
well, i Copied the Thing and i get that error:
Traceback (most recent call last):
File "F:/Python Shit/Waifu2x in Python/i think that is Waifu2x in Python.py", line 4, in
infile, outfile, modelpath = sys.argv[1:]
ValueError: not enough values to unpack (expected 3, got 0)
edit: i did not have an image to convert btw.
where can we find the model?