Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze/crash in web demo on reconstruct_face() #90

Open
sholdingsltd opened this issue Sep 11, 2023 · 0 comments
Open

Freeze/crash in web demo on reconstruct_face() #90

sholdingsltd opened this issue Sep 11, 2023 · 0 comments

Comments

@sholdingsltd
Copy link

sholdingsltd commented Sep 11, 2023

Forgive me for double posting, but I'm having a huge problem with the web demo and thought it might get more attention here. I've been trying to solve it for a while, and I also created a submission on the huggingface repo here: https://huggingface.co/spaces/CVPR/DualStyleGAN/discussions/4

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, and please let me know if I can provide more information!

@sholdingsltd sholdingsltd changed the title Freeze/crash in demo on reconstruct_face() Freeze/crash in web demo on reconstruct_face() Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant