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

OSError: Unable to open file (file signature not found) #23

Closed
pcy190 opened this issue May 5, 2019 · 5 comments
Closed

OSError: Unable to open file (file signature not found) #23

pcy190 opened this issue May 5, 2019 · 5 comments

Comments

@pcy190
Copy link

pcy190 commented May 5, 2019

When I run this sample Usage

import numpy as np
from PIL import Image

img = Image.open(r'MyJPG_Path')
lr_img = np.array(img)

from ISR.models import RDN

rdn = RDN(arch_params={'C':6, 'D':20, 'G':64, 'G0':64, 'x':2})
rdn.model.load_weights('weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5')
sr_img = rdn.predict(lr_img)
Image.fromarray(sr_img)

It warns that:

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    rdn.model.load_weights('weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5')
  File "lib\site-packages\keras\engine\network.py", line 1157, in load_weights
    with h5py.File(filepath, mode='r') as f:
  File "lib\site-packages\h5py\_hl\files.py", line 394, in __init__
    swmr=swmr)
  File "lib\site-packages\h5py\_hl\files.py", line 170, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (file signature not found)

I use the original hdf5 file which is downloaded from the Github source. I wonder how to cope with this problem.

@cfrancesco
Copy link
Collaborator

cfrancesco commented May 6, 2019

Duplicate of #21

If you did use git lfs pull, please comment there.

@cfrancesco cfrancesco marked this as a duplicate of #21 May 6, 2019
@pldeepesh
Copy link

@cfrancesco I have tried to use git lfs pull but it throws an errror,

batch response: This repository is over its data quota. Purchase more data packs to restore access. error: failed to fetch some objects from 'https://github.com/idealo/image-super-resolution.git/info/lfs'

@joys8998
Copy link

joys8998 commented Apr 2, 2020

@cfrancesco Sorry but i get the same error by trying to download weights with git lfs pull command. And i can't use the newest way to load weights (RRDN(weights='gans')) since i want to perform image resolution on a whole directory.

How can i solve?

@cfrancesco
Copy link
Collaborator

cfrancesco commented Apr 2, 2020

I see. You're trying to use the predictor class. It is not maintained, it will probably be removed.

If this is your issue, then it's easy to script: model that way and then iterate through a given directory, something like

from ISR.models import RRDN
from pathlib import Path
import imageio

rrdn = RRDN(weights='gans')
dir_path = Path('/your/img/dir/path')
out_dir_path = Path('output/dir/')

for image in dir_path.iterdir(): 
   if image.endswith('.png'): # or whatever format you have
      image = imageio.imread( dir_path/ image )
      sr_img = rrdn.predict(np.array(image))
      out_image_path = out_dir_path / image
      imageio.imwrite(out_image_path, sr_img)
    

@joys8998
Copy link

joys8998 commented Apr 2, 2020

Yeps, but the amount of images is quite huge and it chashes if i use a for cycle ( also in colab) anyway thank you for your support :)

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

4 participants