0

I wanted to get Featurenet-TensorFlow-2 (see Gitlab) running. I did all the steps mentioned there and ran into this error when I wanted to run train.py:

**D:\python\python.exe C:\Users\***\PycharmProjects\featurenet-tensorflow-2\train.py 
Epoch 1 of 100
Traceback (most recent call last):
File "C:\Users\***\PycharmProjects\featurenet-tensorflow-2\train.py", line 68, in <module>
for step, (x_batch_train, y_batch_train) in enumerate(train_dataloader):
File "C:\Users\***\PycharmProjects\featurenet-tensorflow-2\utils\dataloader.py", line 10, in dataloader_h5
hf = h5py.File(file_path, 'r')
#          ^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\h5py\_hl\files.py", line 567, in __init__
fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
#           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\h5py\_hl\files.py", line 231, 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 106, in h5py.h5f.open
FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = 'data_single_feat/train.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

Process finished with exit code 1**

The Code from Dataloader.py looks like this:

import h5py
import tensorflow as tf
import numpy as np
import utils.binvox_rw as binvox_rw
from create_dataset_splits import zero_centering_norm

def dataloader_h5(file_path):
    hf = h5py.File(file_path, 'r')

    for key in list(hf.keys()):
        group = hf.get(key)
        x = tf.Variable(np.array(group.get("x"), dtype=np.float32), dtype=tf.float32, name="x")
        y = np.array(group.get("y"), dtype=int)

        yield x, y

    hf.close()


def read_voxel_from_binvox(filepath, normalize=True):
    with open(filepath, "rb") as f:
        model = binvox_rw.read_as_3d_array(f)
    voxel = model.data

    if normalize:
        voxel = zero_centering_norm(voxel)

    filename = filepath.split("/")[-1]
    #label = int(filename.split("-")[0])

    voxel = tf.Variable(np.array(voxel, dtype=np.float32), dtype=tf.float32, name="x")
    #label = np.array(label, dtype=np.int8)

    return voxel

So I suppose something with the file path and file name is wrong but I can't figure out what exactly. Thanks for your help.

jjw
  • 1
  • You should probably use an absolute path to your file using the `os` module, as the relative one not only seems to not be working, but will break if you decide to run this script elsewhere. – B Remmelzwaal May 08 '23 at 18:55
  • "So I suppose something with the file path and file name is wrong but I can't figure out what exactly. " Start by checking what the path is; then see the linked duplicate. For future questions, please try to make a [mre] with code that someone else can **copy and paste, without adding or changing anything**, to see the **exact problem, directly**. This involves taking out parts that don't appear to be relevant to the problem, and adding any necessary "driver" code. – Karl Knechtel May 08 '23 at 18:55
  • You're trying to open the file `data_single_feat/train.h5`. Either the folder `data_single_feat` does not exist **in the current directory**, or else that folder does not contain a file named `train.h5`. – John Gordon May 08 '23 at 19:01
  • Thank you so much John!! I created the folder and put the file train.h5 in it and the code is running so far!! – jjw May 08 '23 at 19:07

0 Answers0