Spaces:
Running
Running
Crash/freeze on dualstylegan.py, line 157
#4
by
Tempto
- opened
I've been trying to resolve this issue for about a month and it just refuses to work. Forgive my ignorance as this is the first time I work on something like this. In dualstylegan.py, on line 157, function reconstruct_face:
img_rec, instyle = self.encoder_dict[self.encoder_type](
input_data,
randomize_noise=False,
return_latents=True,
z_plus_latent=z_plus_latent,
return_z_plus_latent=return_z_plus_latent,
resize=False)
The app hangs. I'm using this as a backend for a Flask application, with a very basic frontend where I upload an image and pass its parameters. It gets as far as model.reconstruct_face():
import numpy as np
from PIL import Image
from flask import Blueprint, request
from src.dualstylegan import Model
from src.helpers.send_result import send_result
from src.helpers.send_error import send_bad_request, handle_error
imagestyler_routes = Blueprint('imagestyler', __name__)
def get_style_id(style_type):
style_ids = {
'cartoon': 26,
'caricature': 65,
'arcane': 63,
'pixar': 80
}
return style_ids[style_type]
@imagestyler_routes.route('/imagestyler', methods=['POST'])
def imagestyler():
try:
if 'image' not in request.files:
return send_bad_request('Image is required.')
image_file = request.files['image']
image = Image.open(image_file)
image_array = np.array(image)
style_type = request.form.get('type', 'cartoon')
if style_type not in ['cartoon', 'caricature', 'anime', 'arcane', 'pixar']:
style_type = 'cartoon'
style_id = get_style_id(style_type)
try:
color_weight = float(request.form.get('color_weight', '1'))
except Exception as e:
return handle_error("color weight should be a float number")
try:
structure_weight = float(request.form.get('structure_weight', '0.5'))
except Exception as e:
return handle_error("structure weight should be a float number")
structure_only = request.form.get('structure_only')
if structure_only is not None and (structure_only.lower() == 'true' or structure_only == '1'):
structure_only = True
else:
structure_only = False
encoder_type = request.form.get('encoder_type', 'Z+ encoder (better stylization)')
if encoder_type =='W+ encoder (better reconstruction)':
encoder_type = 'W+ encoder (better reconstruction)'
else:
encoder_type = 'Z+ encoder (better stylization)'
model = Model()
print ("IMAGESTYLER.PY: Model()")
instyle = model.reconstruct_face(image_array, encoder_type)
print ("IMAGESTYLER.PY: model.reconstruct_face(image_array, encoder_type)")
result = model.generate(style_type, style_id, structure_weight, color_weight, structure_only, instyle)
print ("IMAGESTYLER.PY: model.generate(style_type, style_id, structure_weight, color_weight, structure_only, instyle)")
return send_result(result)
except Exception as e:
return handle_error(e)
I'm even using a demo image. The problem is when it gets to that line, the app just freezes and debugging it has been a nightmare because nothing in the logs looks wrong. Thanks in advance.