cog icon indicating copy to clipboard operation
cog copied to clipboard

panic:runtime error

Open tzktz opened this issue 1 year ago • 7 comments

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8ad41b]

goroutine 1 [running]:
github.com/replicate/cog/pkg/cli.predictIndividualInputs({{{0x0, 0x0, 0x0}, {0xc000234250, 0x1, 0x1}, {0x0, 0x0}, {0xc000027278, 0x16}, ...}, ...}, ...)
        /home/runner/work/cog/cog/pkg/cli/predict.go:198 +0x41b
github.com/replicate/cog/pkg/cli.cmdPredict(0xc000005200?, {0xc0001b6680?, 0x4?, 0x4?})
        /home/runner/work/cog/cog/pkg/cli/predict.go:153 +0x9be
github.com/spf13/cobra.(*Command).execute(0xc000005200, {0xc0001b6640, 0x4, 0x4})
        /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)
        /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).Execute(0xd92780?)
        /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:992 +0x19
main.main()
        /home/runner/work/cog/cog/cmd/cog/cog.go:14 +0x6f

can anyone fix this ?

tzktz avatar Nov 16 '23 12:11 tzktz

Hi @tzktz. Can you share any details about what you did to produce this error? It'd be helpful to know what version of Cog you're using, what command you ran, and what your project looks like.

mattt avatar Nov 16 '23 12:11 mattt

hi @mattt

here is my predict.py file

from PIL import Image
from rembg import remove, new_session
import tempfile
from cog import BasePredictor, Input, Path
from pathlib import Path
class Predictor(BasePredictor):

    def predict(
            self, input_image_path: str,
            model: str = Input(description="select model",
                               choices=["u2net", "u2net_human_seg", "u2net_cloth_seg", "u2netp"],
                               default="u2net_human_seg")
    ) -> str:
        if not input_image_path:
            raise ValueError("No input image selected")

        input_image = Image.open(input_image_path)
        # Remove background
        match model:
            case "u2net":
                model = u2net
            case "u2net_human_seg":
                model = u2net_human_seg
            case "u2net_cloth_seg":
                model = u2net_cloth_seg
            case "u2netp":
                model = u2netp
        model_name = model
        session = new_session(model_name)
        output_image = remove(input_image, session=session)

        background_color = (192, 192, 192)

        new_image = Image.new("RGB", input_image.size, background_color)

        # Paste the original input image (with the background removed) onto the new image
        new_image.paste(output_image, (0, 0), output_image)

        output_path = Path(tempfile.mkdtemp()) / "color_change_background.jpg"
        new_image.save(output_path)

        return str(output_path)

run command : $ cog predict -i [email protected] -i model=u2net_human_seg

tzktz avatar Nov 17 '23 05:11 tzktz

cog version : 0.8.6 python : 3.10 os : ubuntu 22

tzktz avatar Nov 17 '23 05:11 tzktz

@tzktz Thanks for sharing that. Cog is crashing around the code where it's handling prediction output. I think the problem is that your predictor is returning a str instead of the path itself. Can you try updating your predict function to return Path? You can find an example of how to do this with image generation models like SDXL.

mattt avatar Nov 17 '23 11:11 mattt

@tzktz Thanks for sharing that. Cog is crashing around the code where it's handling prediction output. I think the problem is that your predictor is returning a str instead of the path itself. Can you try updating your predict function to return Path? You can find an example of how to do this with image generation models like SDXL.

@mattt after return predict function to path face the same error.. could u help me to rectify this issue

tzktz avatar Nov 18 '23 05:11 tzktz

hello, could you solve this? i'm facing the same issue

alesuae avatar Jan 02 '24 20:01 alesuae

@alesuae uninstall cog and reinstall it..it will works fine

tzktz avatar Jan 03 '24 04:01 tzktz