0

I am currently doing an assignment on deep learning by downloading the assignment files from github.

import numpy as np
import matplotlib.pyplot as plt
import h5py
import scipy
from PIL import Image
from scipy import ndimage
from lr_utils import load_dataset

%matplotlib inline

You are given a dataset ("data.h5") containing: - a training set of m_train images labeled as cat (y=1) or non-cat (y=0) - a test set of m_test images labeled as cat or non-cat - each image is of shape (num_px, num_px, 3) where 3 is for the 3 channels (RGB). Thus, each image is square (height = num_px) and (width = num_px).

# Loading the data (cat/non-cat)
train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()

I ran the setup.sh file too but the error doesn't seem to go away.enter image description here

lr_utils.py file:

import numpy as np
import h5py
    
    
def load_dataset():
    train_dataset = h5py.File('datasets/train_catvnoncat.h5', "r")
    train_set_x_orig = np.array(train_dataset["train_set_x"][:]) # your train set features
    train_set_y_orig = np.array(train_dataset["train_set_y"][:]) # your train set labels

    test_dataset = h5py.File('datasets/test_catvnoncat.h5', "r")
    test_set_x_orig = np.array(test_dataset["test_set_x"][:]) # your test set features
    test_set_y_orig = np.array(test_dataset["test_set_y"][:]) # your test set labels

    classes = np.array(test_dataset["list_classes"][:]) # the list of classes
    
    train_set_y_orig = train_set_y_orig.reshape((1, train_set_y_orig.shape[0]))
    test_set_y_orig = test_set_y_orig.reshape((1, test_set_y_orig.shape[0]))
    
    return train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes

Kindly help!

Utkarsh A
  • 13
  • 1
  • 3
  • Does this answer your question? [Error opening file in H5PY (File signature not found)](https://stackoverflow.com/questions/38089950/error-opening-file-in-h5py-file-signature-not-found) – DYZ Dec 14 '21 at 05:52
  • I can give you this advice, ==> check your list of .h5 files, I, navely, had a long list and I had a .py File inthere, so I had always this message error "unable to open file (file signature not found)" – h.a.c.h Mar 07 '22 at 11:03
  • You might want to take a look at ["_Why is "Can someone help me?" not an actual question?_"](https://meta.stackoverflow.com/q/284236/20170164) – rainbow.gekota Nov 01 '22 at 19:30

3 Answers3

0

I solved the issue by downloading uncorrupted .h5 files and putting them in the folder datasets/ in the same directory.

ouflak
  • 2,458
  • 10
  • 44
  • 49
0

The files you downloaded are corrupted. You can visit https://github.com/abdur75648/Deep-Learning-Specialization-Coursera to download the uncorrupted files.

0

you can download uncorrupted files from here : https://www.kaggle.com/datasets/muhammeddalkran/catvnoncat

and replace it in the directory of the corrupted files