MarcoForte / FBA_Matting

Official repository for the paper F, B, Alpha Matting
MIT License
464 stars 95 forks source link

AttributeError: 'Args' object has no attribute 'seek'. in notebook #50

Open Ishihara-Masabumi opened 2 years ago

Ishihara-Masabumi commented 2 years ago

Using FBA Matting.ipynb in Gooble Colab, at the source code below,

class Args:
  encoder = 'resnet50_GN_WS'
  decoder = 'fba_decoder'
  weights = 'FBA.pth'
args=Args()
try:
    model = build_model(args)
except:
    !gdown  https://drive.google.com/uc?id=1T_oiKDE_biWf2kqexMEN7ObWqtXAzbB1
    model = build_model(args)

the following error occurred.

modifying input layer to accept 11 channels
Downloading...
From: https://drive.google.com/uc?id=1T_oiKDE_biWf2kqexMEN7ObWqtXAzbB1
To: /content/drive/MyDrive/FBA Matting/FBA.pth
100% 139M/139M [00:01<00:00, 81.2MB/s]
modifying input layer to accept 11 channels
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.7/dist-packages/torch/serialization.py](https://localhost:8080/#) in _check_seekable(f)
    307     try:
--> 308         f.seek(f.tell())
    309         return True

AttributeError: 'Args' object has no attribute 'seek'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
14 frames
AttributeError: 'Args' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
AttributeError: 'Args' object has no attribute 'seek'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.7/dist-packages/torch/serialization.py](https://localhost:8080/#) in raise_err_msg(patterns, e)
    302                                 + " Please pre-load the data into a buffer like io.BytesIO and"
    303                                 + " try to load from it instead.")
--> 304                 raise type(e)(msg)
    305         raise e
    306 

AttributeError: 'Args' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

Please tell me the cause of the error and how to fix it.

Tieck-IT commented 1 year ago

modify build_model( ) from networks.models like this.


def build_model(weights):
    import io
    weights = weights.weights
    net_encoder = fba_encoder()

    net_decoder = fba_decoder()

    model = MattingModule(net_encoder, net_decoder)

    if(weights != 'default'):
        with open(weights, 'rb') as f:
            buffer = io.BytesIO(f.read())
        # sd = torch.load(weights)
        sd = torch.load(buffer)
        model.load_state_dict(sd, strict=True)

    return model
maomao2991 commented 1 year ago

the same, useless

rohanblkbox commented 11 months ago

Got the solution?

IndraKumari0703 commented 11 months ago

Anyone found the solution??

Tieck-IT commented 10 months ago

It still work at colab. If you want to modify and apply module(e.g. .py) at colab, first modify module and second restart runtime.

image image

modify build_model( ) from networks.models like this.

def build_model(weights):
    import io
    weights = weights.weights
    net_encoder = fba_encoder()

    net_decoder = fba_decoder()

    model = MattingModule(net_encoder, net_decoder)

    if(weights != 'default'):
        with open(weights, 'rb') as f:
            buffer = io.BytesIO(f.read())
        # sd = torch.load(weights)
        sd = torch.load(buffer)
        model.load_state_dict(sd, strict=True)

    return model