othmbela / dbn-based-nids

An Intrusion Detection System based on Deep Belief Networks
Apache License 2.0
70 stars 16 forks source link

A problem about the code implementation of ‘An Intrusion Detection System based on Deep Belief Networks’ #3

Open Sandrw opened 1 year ago

Sandrw commented 1 year ago

Hello, I feel deeply after reading your paper 'An Intrusion Detection System based on Deep Belief Networks'. I have to say, your ideas and abilities are great.But I have a question. Your paper mentioned that the "Infiltration" class was deleted when merging classes. According to Table 1: Class distribution of CICIDS2017 dataset, the merged dataset should only have 6 classes, There are also 6 classes in the deepBeliefNetwork.json file, but why do I implement the code when n Classes=6 will report an error, n Only when classes=7 can I run?I look forward to your reply. Thank you!

othmbela commented 1 year ago

Hello @Sandrw,

Thank you for your comment.

I'm not sure I understand your question, but I'll try to give you some details on the implementation.

Indeed the Infiltration class was removed when merging the classes, and we ended up with 6classes. Therefore, I used 6nodes on the output layer (one node representing one class) for my DL models. Do you have any errors when running the code with n_classes=6? If so, could you please give some details on the error?

If you have more or fewer classes (for e.g. keeping the Infiltration class), you will need to specify the correct number of output nodes.

Please let me know if this could help.

Sandrw commented 1 year ago
Traceback (most recent call last):
  File "main.py", line 202, in <module>
    main(config)
  File "main.py", line 76, in main
    train_history = train(
  File "/root/autodl-tmp/DBN/utils/train.py", line 95, in train
    loss.backward()
  File "/root/miniconda3/lib/python3.8/site-packages/torch/_tensor.py", line 487, in backward
    torch.autograd.backward(
  File "/root/miniconda3/lib/python3.8/site-packages/torch/autograd/__init__.py", line 197, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)`
../aten/src/ATen/native/cuda/Loss.cu:242: nll_loss_forward_reduce_cuda_kernel_2d: block: [0,0,0], thread: [27,0,0] Assertion `t >= 0 && t < n_classes` failed.
othmbela commented 1 year ago

What is your environment? What are the parameters used?

Also, are you using Cuda to run the experiments? If so, could please confirm if you have the same issue when using the CPUs?

Sandrw commented 1 year ago

Yes, I used CUDA Version: 11.7. Because of the version correspondence problem, I used torch Version: 1.13.0. I think it will run faster on the GPUs than on the CPUs, so I didn't try it on the CPUs

othmbela commented 1 year ago

Could you please try it on the CPUs just to check if it's still throwing the error?

Sandrw commented 1 year ago

OK,I'll try it.Thank you for your reply!

Sandrw commented 1 year ago

Hello, I tried to run on CPUs, but the same problem occurred when I ran on GPUs for the first time. The error "IndexError: Target 6 is out of bounds." The following is its error details

Traceback (most recent call last):
  File "main.py", line 203, in <module>
    main(config)
  File "main.py", line 77, in main
    train_history = train(
  File "/root/autodl-tmp/DBN/utils/train.py", line 94, in train
    loss = criterion(outputs, labels)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/loss.py", line 1120, in forward
    return F.cross_entropy(input, target, weight=self.weight,
  File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/functional.py", line 2824, in cross_entropy
    return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
IndexError: Target 6 is out of bounds.
Sandrw commented 1 year ago

Hello, I searched the relevant information on the Internet, and the answer is basically two kinds, one is that the label doesn’t start from 0, the other is that n_ class and the number of nodes in the output layers are different. However, neither of them can solve the problem. In addition, I ran on the CPU again, and the result shows that it may not be a problem of the environment.

I would be grateful if you could give me some guidance. I will look forward to your reply!

Sandrw commented 1 year ago

Hello,@othmbela, I have tried other methods, but I still haven't solved this problem. If you have time, could you give me some guidance? I really sincerely look forward to your reply

BlackRxing commented 1 year ago

Hello, I searched the relevant information on the Internet, and the answer is basically two kinds, one is that the label doesn’t start from 0, the other is that n_ class and the number of nodes in the output layers are different. However, neither of them can solve the problem. In addition, I ran on the CPU again, and the result shows that it may not be a problem of the environment.

I would be grateful if you could give me some guidance. I will look forward to your reply!

i ran on cpu and encounter the same problem, do you mean when you run again, the result becomes normal? Have you found the solution my friend.

Sandrw commented 1 year ago

I remember that finally, I found some small problems with the dataset. After the modification, I put the code on the CPU, and the problem was solved inexplicably. However, I don't think it was caused by the problem with the dataset. I feel that the situation is very mysterious, so I'm sorry I didn't provide you with useful information

刘小志 @.***

 

------------------ 原始邮件 ------------------ 发件人: "othmbela/dbn-based-nids" @.>; 发送时间: 2022年12月8日(星期四) 晚上9:29 @.>; @.**@.>; 主题: Re: [othmbela/dbn-based-nids] A problem about the code implementation of ‘An Intrusion Detection System based on Deep Belief Networks’ (Issue #3)

Hello, I searched the relevant information on the Internet, and the answer is basically two kinds, one is that the label doesn’t start from 0, the other is that n_ class and the number of nodes in the output layers are different. However, neither of them can solve the problem. In addition, I ran on the CPU again, and the result shows that it may not be a problem of the environment.

I would be grateful if you could give me some guidance. I will look forward to your reply!

i ran on cpu and encounter the same problem, do you mean when you run again, the result becomes normal? Have you found the solution my friend.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

ssbagja commented 1 year ago

I remember that finally, I found some small problems with the dataset. After the modification, I put the code on the CPU, and the problem was solved inexplicably. However, I don't think it was caused by the problem with the dataset. I feel that the situation is very mysterious, so I'm sorry I didn't provide you with useful information 刘小志 @.   ------------------ 原始邮件 ------------------ 发件人: "othmbela/dbn-based-nids" @.>; 发送时间: 2022年12月8日(星期四) 晚上9:29 @.>; @*.**@*.>; 主题: Re: [othmbela/dbn-based-nids] A problem about the code implementation of ‘An Intrusion Detection System based on Deep Belief Networks’ (Issue #3) Hello, I searched the relevant information on the Internet, and the answer is basically two kinds, one is that the label doesn’t start from 0, the other is that n_ class and the number of nodes in the output layers are different. However, neither of them can solve the problem. In addition, I ran on the CPU again, and the result shows that it may not be a problem of the environment. I would be grateful if you could give me some guidance. I will look forward to your reply! i ran on cpu and encounter the same problem, do you mean when you run again, the result becomes normal? Have you found the solution my friend. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.>

i have the same problem, IndexError: Target 6 is out of bounds. can you help me how to fix the problem, thank you before

superyuey commented 1 year ago

Hello, I also encounter this problem while running the code. I think the reason is the unmatched code between data preprocessing and mainning process. Data preprocessing grouped labels into 7 classes inluding infiltration, but main process set a 6 labels list without infiltration class. The code ran successfully when I added infiltration class in main.py.

han-x-z commented 1 year ago

Hello, I also encounter this problem while running the code. I think the reason is the unmatched code between data preprocessing and mainning process. Data preprocessing grouped labels into 7 classes inluding infiltration, but main process set a 6 labels list without infiltration class. The code ran successfully when I added infiltration class in main.py.

can you show me how you add infiltration clss in main.py your code screenshot

limingjindev commented 1 year ago

你好,我在运行代码的时候也遇到了这个问题。我认为原因是数据预处理和维护过程之间的代码不匹配。数据预处理将标签分为 7 个类别,包括渗透,但主过程设置了一个没有渗透类别的 6 个标签列表。当我在 main.py 中添加渗透类时,代码运行成功。 Can you send me an email with the modified code? 1378506591@qq.com

SUSHANTH009 commented 4 months ago
Screenshot 2024-02-18 at 12 48 00 PM

even i am facing the same issue.please can someone help

Sandrw commented 4 months ago
        This error occurred, "Target 6 is out of bounds.". In general, it may be because the number of labels in the dataset is<=6, while the number of target classes set in the code is>6. Please carefully check the number of target classes in the processed dataset. Due to time constraints, I can't remember exactly where the problem lies, but it's roughly in this direction. Good luck to you

                    ***@***.***

---- Replied Message ----

     From 

        ***@***.***>

     Date 

    2/18/2024 15:18

     To 

        ***@***.***>

     Cc 

        Zhihua ***@***.***>
        ,

        ***@***.***>

     Subject 

          Re: [othmbela/dbn-based-nids] A problem about the code implementation of ‘An Intrusion Detection System based on Deep Belief Networks’ (Issue #3)

Screenshot.2024-02-18.at.12.48.00.PM.png (view on web) even i am facing the same issue.please can someone help

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>