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

ValueError: Unknown layer: Bidirectional in rnn-cc-detection.py #330

Closed
naturalnetworks opened this issue Apr 30, 2023 · 3 comments
Closed
Assignees

Comments

@naturalnetworks
Copy link
Contributor

Describe the bug
During capture from an interface, the following error pops up quite often.

Traceback (most recent call last):
  File "/home/user/StratosphereLinuxIPS/modules/rnn-cc-detection/rnn-cc-detection.py", line 121, in run
    tcpmodel = load_model(model_file)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/slips/lib/python3.11/site-packages/tensorflow/python/keras/saving/save.py", line 200, in load_model
    return hdf5_format.load_model_from_hdf5(filepath, custom_objects,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/slips/lib/python3.11/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 180, in load_model_from_hdf5
    model = model_config_lib.model_from_config(model_config,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/slips/lib/python3.11/site-packages/tensorflow/python/keras/saving/model_config.py", line 52, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/slips/lib/python3.11/site-packages/tensorflow/python/keras/layers/serialization.py", line 118, in deserialize
    return generic_utils.deserialize_keras_object(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/slips/lib/python3.11/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 674, in deserialize_keras_object
    deserialized_obj = cls.from_config(
                       ^^^^^^^^^^^^^^^^
  File "/home/user/slips/lib/python3.11/site-packages/tensorflow/python/keras/engine/sequential.py", line 496, in from_config
    layer = layer_module.deserialize(layer_config,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/slips/lib/python3.11/site-packages/tensorflow/python/keras/layers/serialization.py", line 118, in deserialize
    return generic_utils.deserialize_keras_object(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/slips/lib/python3.11/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 659, in deserialize_keras_object
    (cls, cls_config) = class_and_config_for_serialized_keras_object(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/slips/lib/python3.11/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 556, in class_and_config_for_serialized_keras_object
    raise ValueError(
ValueError: Unknown layer: Bidirectional. Please ensure this object is passed to the `custom_objects` argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

Note that I am receiving a TZSP stream from a router and replaying it to a dummy interface.

To Reproduce
Steps to reproduce the behavior:

  1. Set network interface to promisc (or use a dummy interface with tcpreplay)
  2. ./slips.py -c config/slips.conf -i
  3. Confirm data eg tcpdump -i -c 10
  4. Wait for error to appear

Expected behavior
No value errors should appear during normal operation/during an interface capture.

Branch
Have tested both Master and Develop, issue seen on both.

Environment (please complete the following information):

  • OS: Ubuntu (Raspberri Pi/ARM64)
  • Version: 23.04 (Linux 6.2.0-1004-raspi)
  • Python version: Python 3.11.2
  • Are you running slips in docker or locally? Locally

Additional context

This is running on a Raspberry Pi 4, no GPU (or NPU).

I'm using the following python modules:

tensorflow==2.12.0
keras==2.12.0

Really guessing here, but the following made the error go away but I have no idea of the ramifications. Just doing what the error told me to do :)

At the beginning of rnn-cc-detection.py, load an additional class and assign a variable.

from tensorflow.keras.layers import Bidirectional

custom_objects = {'Bidirectional': Bidirectional}

Then change the following line to pass it along to the load_model method via its custom_objects argument:

            # tcpmodel = load_model(model_file) 
            tcpmodel = load_model(model_file, custom_objects=custom_objects)
@eldraco eldraco self-assigned this May 23, 2023
@eldraco
Copy link
Collaborator

eldraco commented Feb 13, 2024

Working on this one

@eldraco eldraco mentioned this issue Feb 13, 2024
6 tasks
@eldraco
Copy link
Collaborator

eldraco commented Feb 14, 2024

Ok it is fixed. Now waiting for PR to be merged

@naturalnetworks
Copy link
Contributor Author

Thanks Sebastian, I'll give it a go once it has been merged.

@AlyaGomaa AlyaGomaa added this to Slips Jul 12, 2024
@github-project-automation github-project-automation bot moved this to Todo in Slips Jul 12, 2024
@eldraco eldraco added this to the Fix the ML models milestone Jul 13, 2024
@AlyaGomaa AlyaGomaa moved this from Todo to Working on it in Slips Jul 15, 2024
@eldraco eldraco moved this from Working on it to Done in Slips Jul 16, 2024
@eldraco eldraco closed this as completed by moving to Done in Slips Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants