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

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

Open
Ishihara-Masabumi opened this issue Sep 12, 2022 · 5 comments

Comments

@Ishihara-Masabumi
Copy link

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
Copy link

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
Copy link

the same, useless

@rohanblkbox
Copy link

Got the solution?

@IndraKumari0703
Copy link

Anyone found the solution??

@Tieck-IT
Copy link

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
    

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

5 participants