Skip to content

ValueError: Argument name must be a string and cannot contain character /. Received: name=0/0/generic/d1 (of type <class 'str'>) #75

@raphael10-collab

Description

@raphael10-collab
(base) raphy@raohy:~/n-beats$ python -m venv .n-beats
(base) raphy@raohy:~/n-beats$ source .n-beats/bin/activate

(.n-beats) (base) raphy@raohy:~/n-beats$ pip install --upgrade pip

(.n-beats) (base) raphy@raohy:~/n-beats$ pip install nbeats-keras

(.n-beats) (base) raphy@raohy:~/n-beats$ pip install nbeats-pytorch

(.n-beats) (base) raphy@raohy:~/n-beats/examples$ pip install scikit-learn

(.n-beats) (base) raphy@raohy:~/n-beats/examples$ cat examples-requirements.txt
wfdb==2.2.1

(.n-beats) (base) raphy@raohy:~/n-beats/examples$ pip install -r examples-requirements.txt
Collecting wfdb==2.2.1 (from -r examples-requirements.txt (line 1))
  Using cached wfdb-2.2.1.tar.gz (94 kB)
  Preparing metadata (setup.py) ... done
Collecting nose>=1.3.7 (from wfdb==2.2.1->-r examples-requirements.txt (line 1))
  Using cached nose-1.3.7-py3-none-any.whl.metadata (1.7 kB)
Requirement already satisfied: numpy>=1.11.0 in /home/raphy/n-beats/.n-beats/lib/python3.12/site-packages (from wfdb==2.2.1->-r examples-requirements.txt (line 1)) (2.3.2)
Requirement already satisfied: matplotlib>=1.5.1 in /home/raphy/n-beats/.n-beats/lib/python3.12/site-packages (from wfdb==2.2.1->-r examples-requirements.txt (line 1)) (3.10.5)
Requirement already satisfied: requests>=2.10.0 in /home/raphy/n-beats/.n-beats/lib/python3.12/site-packages (from wfdb==2.2.1->-r examples-requirements.txt (line 1)) (2.32.5)
Requirement already satisfied: pandas>=0.19.1 in /home/raphy/n-beats/.n-beats/lib/python3.12/site-packages (from wfdb==2.2.1->-r examples-requirements.txt (line 1)) (2.3.2)
Requirement already satisfied: scipy>=0.19.0 in /home/raphy/n-beats/.n-beats/lib/python3.12/site-packages (from wfdb==2.2.1->-r examples-requirements.txt (line 1)) (1.16.1)
Collecting sklearn>=0.0 (from wfdb==2.2.1->-r examples-requirements.txt (line 1))
  Using cached sklearn-0.0.post12.tar.gz (2.6 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [15 lines of output]
      The 'sklearn' PyPI package is deprecated, use 'scikit-learn'
      rather than 'sklearn' for pip commands.

      Here is how to fix this error in the main use cases:
      - use 'pip install scikit-learn' rather than 'pip install sklearn'
      - replace 'sklearn' by 'scikit-learn' in your pip requirements files
        (requirements.txt, setup.py, setup.cfg, Pipfile, etc ...)
      - if the 'sklearn' package is used by one of your dependencies,
        it would be great if you take some time to track which package uses
        'sklearn' instead of 'scikit-learn' and report it to their issue tracker
      - as a last resort, set the environment variable
        SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True to avoid this error

      More information is available at
      https://github.com/scikit-learn/sklearn-pypi-package
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

(.n-beats) (base) raphy@raohy:~/n-beats$ nano simple.py :

# https://github.com/philipperemy/n-beats/tree/master?tab=readme-ov-file#example

import warnings

import numpy as np

from nbeats_keras.model import NBeatsNet as NBeatsKeras
from nbeats_pytorch.model import NBeatsNet as NBeatsPytorch

warnings.filterwarnings(action='ignore', message='Setting attributes')


def main():
    # https://keras.io/layers/recurrent/
    # At the moment only Keras supports input_dim > 1. In the original paper, input_dim=1.
    num_samples, time_steps, input_dim, output_dim = 50_000, 10, 1, 1

    # This example is for both Keras and Pytorch. In practice, choose the one you prefer.
    for BackendType in [NBeatsKeras, NBeatsPytorch]:
        # NOTE: If you choose the Keras backend with input_dim>1, you have 
        # to set the value here too (in the constructor).
        backend = BackendType(
            backcast_length=time_steps, forecast_length=output_dim,
            stack_types=(NBeatsKeras.GENERIC_BLOCK, NBeatsKeras.GENERIC_BLOCK),
            nb_blocks_per_stack=2, thetas_dim=(4, 4), share_weights_in_stack=True,
            hidden_layer_units=64
        )

        # Definition of the objective function and the optimizer.
        backend.compile(loss='mae', optimizer='adam')

        # Definition of the data. The problem to solve is to find f such as | f(x) - y | -> 0.
        # where f = np.mean.
        x = np.random.uniform(size=(num_samples, time_steps, input_dim))
        y = np.mean(x, axis=1, keepdims=True)

        # Split data into training and testing datasets.
        c = num_samples // 10
        x_train, y_train, x_test, y_test = x[c:], y[c:], x[:c], y[:c]
        test_size = len(x_test)

        # Train the model.
        print('Training...')
        backend.fit(x_train, y_train, validation_data=(x_test, y_test), epochs=20, batch_size=128)

        # Save the model for later.
        backend.save('n_beats_model.h5')

        # Predict on the testing set (forecast).
        predictions_forecast = backend.predict(x_test)
        np.testing.assert_equal(predictions_forecast.shape, (test_size, backend.forecast_length, output_dim))

        # Predict on the testing set (backcast).
        predictions_backcast = backend.predict(x_test, return_backcast=True)
        np.testing.assert_equal(predictions_backcast.shape, (test_size, backend.backcast_length, output_dim))

        # Load the model.
        model_2 = BackendType.load('n_beats_model.h5')

        np.testing.assert_almost_equal(predictions_forecast, model_2.predict(x_test))


if __name__ == '__main__':
    main()

I'm getting this error message:

(.n-beats) (base) raphy@raohy:~/n-beats$ python simple.py 
2025-08-27 14:51:25.261953: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "/home/raphy/n-beats/simple.py", line 64, in <module>
    main()
  File "/home/raphy/n-beats/simple.py", line 22, in main
    backend = BackendType(
              ^^^^^^^^^^^^
  File "/home/raphy/n-beats/nbeats_keras/model.py", line 83, in __init__
    backcast, forecast = self.create_block(x_, e_, stack_id, block_id, stack_type, nb_poly)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/raphy/n-beats/nbeats_keras/model.py", line 169, in create_block
    d1 = reg(Dense(self.units, activation='relu', name=n('d1')))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/raphy/n-beats/.n-beats/lib/python3.12/site-packages/keras/src/layers/core/dense.py", line 92, in __init__
    super().__init__(activity_regularizer=activity_regularizer, **kwargs)
  File "/home/raphy/n-beats/.n-beats/lib/python3.12/site-packages/keras/src/layers/layer.py", line 273, in __init__
    Operation.__init__(self, name=name)
  File "/home/raphy/n-beats/.n-beats/lib/python3.12/site-packages/keras/src/ops/operation.py", line 23, in __init__
    raise ValueError(
ValueError: Argument `name` must be a string and cannot contain character `/`. Received: name=0/0/generic/d1 (of type <class 'str'>)

(.n-beats) (base) raphy@raohy:~/n-beats$ python --version
Python 3.12.8

OS: Ubuntu 24.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions