mrhan1993 / Fooocus-API

FastAPI powered API for Fooocus
GNU General Public License v3.0
505 stars 132 forks source link

Issue with FaceSwap #296

Closed nandan-06 closed 2 months ago

nandan-06 commented 2 months ago

I'm getting this error: TypeError: ResNet.__init__() got an unexpected keyword argument 'weights'

This is my route:


def img_post():
    image_id = 24
    if not image_id:
        return jsonify({"error": "No image ID found in session"}), 404

    image_path = os.path.join(image_directory, f'{image_id}.png')
    if not os.path.exists(image_path):
        abort(404, description="Image not found")

    prompt = request.form['prompt']  

    with open(image_path, 'rb') as image_file:
        image_data = image_file.read()

    url = "http://127.0.0.1:8888/v1/generation/image-prompt"

    files = {
        'cn_img1': ('image.png', image_data, 'image/png'), 
    }
    data = {
        'prompt': prompt,
        'cn_type1': 'FaceSwap',
        'cn_img1': ('image.png', image_data, 'image/png'),
        'async_process': 'false',  
    }

    try:
        response = requests.post(url, data=data, files=files)
        response.raise_for_status()
        result = response.json()    
        return result
    except requests.exceptions.RequestException as e:
        return jsonify({"error": str(e), "status_code": response.status_code}), 500```
mrhan1993 commented 2 months ago

I tried with this code, is ok, what is your version. or you can support more detail, like output in consoles

import jsonify
import os
import requests

def img_post():
    image_id = 'source_face_man'
    if not image_id:
        return jsonify({"error": "No image ID found in session"}), 404

    image_path = os.path.join('E:\Fooocus-API\examples\imgs', f'{image_id}.png')
    if not os.path.exists(image_path):
        os.abort(404, description="Image not found")

    prompt = 'prompt'

    with open(image_path, 'rb') as image_file:
        image_data = image_file.read()

    url = "http://127.0.0.1:8888/v1/generation/image-prompt"

    files = {
        'cn_img1': ('image.png', image_data, 'image/png'), 
    }
    data = {
        'prompt': prompt,
        'cn_type1': 'FaceSwap',
        'cn_img1': ('image.png', image_data, 'image/png'),
        'async_process': 'false',  
    }

    try:
        response = requests.post(url, data=data, files=files)
        response.raise_for_status()
        result = response.json()    
        return result
    except requests.exceptions.RequestException as e:
        return jsonify({"error": str(e), "status_code": response.status_code})

img_post()
nandan-06 commented 2 months ago

image

torch version: 1.11.0 torchvision version: 0.12.0

mrhan1993 commented 2 months ago

Based on the error information you provided, I have tested version v0.3.32, but I still have not encountered this error. If there are no special requirements, I would suggest you upgrade, which includes both the main program and the dependent environment.

nandan-06 commented 2 months ago

My version is v0.3.30 How can I upgrade my version to v0.3.32

nandan-06 commented 2 months ago

Update:

path: /repositories/Fooocus/extras/facexlib/detection/retinaface.py

Change the line: backbone = models.resnet50(weights=None)

To:

backbone = models.resnet50(pretrained=None)

This has solved my error.