DanielLin1986 / Function-level-Vulnerability-Detection

A deep learning-based vulnerability detection framework
74 stars 23 forks source link

UnboundLocalError: local variable 'test_list_id' referenced before assignment #15

Open aravinthk00 opened 2 years ago

aravinthk00 commented 2 years ago

****This my error when I try to test the model , please give me solution and guidelines

(myenv) C:\Users\30863\Function-level-Vulnerability-Detection-master>python main.py --config config\config.yaml --test --trained_model C:\Users\30863\Function-level-Vulnerability-Detection-master\result\models\test_model_01_0.920_0.334828.h5 Using TensorFlow backend. 2022-08-04 16:53:45.929112: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found 2022-08-04 16:53:45.929253: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. [INFO] Start testing process.... [INFO] Loading data from C:\Users\30863\Function-level-Vulnerability-Detection-master\data/.... [INFO] The length of the loaded data list is : 622 [INFO] Pad the sequence to unified length... [INFO] Patition the data .... [INFO] There are 125 total samples in the test set. 9 vulnerable samples. Traceback (most recent call last): File "main.py", line 34, in helper.exec() File "C:\Users\30863\Function-level-Vulnerability-Detection-master\src\helper.py", line 346, in exec test_set_x, test_set_y, test_set_id = self.loadTestSet() File "C:\Users\30863\Function-level-Vulnerability-Detection-master\src\helper.py", line 332, in loadTestSet return test_set_x, test_set_y, test_list_id UnboundLocalError: local variable 'test_list_id' referenced before assignment

DanielLin1986 commented 2 years ago

****This my error when I try to test the model , please give me solution and guidelines

(myenv) C:\Users\30863\Function-level-Vulnerability-Detection-master>python main.py --config config\config.yaml --test --trained_model C:\Users\30863\Function-level-Vulnerability-Detection-master\result\models\test_model_01_0.920_0.334828.h5 Using TensorFlow backend. 2022-08-04 16:53:45.929112: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found 2022-08-04 16:53:45.929253: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. [INFO] Start testing process.... [INFO] Loading data from C:\Users\30863\Function-level-Vulnerability-Detection-master\data/.... [INFO] The length of the loaded data list is : 622 [INFO] Pad the sequence to unified length... [INFO] Patition the data .... [INFO] There are 125 total samples in the test set. 9 vulnerable samples. Traceback (most recent call last): File "main.py", line 34, in helper.exec() File "C:\Users\30863\Function-level-Vulnerability-Detection-master\src\helper.py", line 346, in exec test_set_x, test_set_y, test_set_id = self.loadTestSet() File "C:\Users\30863\Function-level-Vulnerability-Detection-master\src\helper.py", line 332, in loadTestSet return test_set_x, test_set_y, test_list_id UnboundLocalError: local variable 'test_list_id' referenced before assignment

This error has been fixed, please try it again. Thanks.

DanielLin1986 commented 2 years ago

For the ELMo, if you want to perform testing, please do it when the model is just finished training.

If you save the trained model in a directory, then load it, and perform the test, the model would not be able to be loaded. Please kindly let me know if you can find a way to load the model.

image

aravinthk00 commented 2 years ago

I used latest helper.py but error not fix and I get same error log

aravinthk00 commented 2 years ago

when I use to latest helper.py in train the model , I getting tensorflow.python.framework.errors_impl.NotFoundError

(myenv) C:\Users\30863\Function-level-Vulnerability-Detection-master>Python main.py --config config\config.yaml --data_dir C:\Users\30863\Function-level-Vulnerability-Detection-master\data --embedding ELMo Using TensorFlow backend. 2022-08-08 21:44:41.499118: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found 2022-08-08 21:44:41.499235: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. [INFO] Start training process.... [INFO] Loading data from C:\Users\30863\Function-level-Vulnerability-Detection-master\C:\Users\30863\Function-level-Vulnerability-Detection-master\data.... [INFO] The length of the loaded data list is : 622 [INFO] Applying ELMo model! [INFO] Setting padding length 1000 for ELMo model. Each textual sequence contains 1000 elements. [INFO] Patition the data .... [INFO] Data processing completed! [INFO] ------------------------------------------------------- [INFO] There are 397 total samples in the training set. 28 vulnerable samples. [INFO] There are 100 total samples in the validation set. 8 vulnerable samples. [INFO] ------------------------------------------------------- 2022-08-08 21:44:44.409825: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 2022-08-08 21:44:44.422662: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found 2022-08-08 21:44:44.422872: E tensorflow/stream_executor/cuda/cuda_driver.cc:318] failed call to cuInit: UNKNOWN ERROR (303) 2022-08-08 21:44:44.433014: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: 30863-436055 2022-08-08 21:44:44.433328: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: 30863-436055 [INFO] No GPU detected. [INFO] Using CPU for training. It may take considerable time! [INFO] Loading the elmo model. WARNING:tensorflow:From C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\keras\backend\tensorflow_backend.py:74: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\keras\backend\tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

Traceback (most recent call last): File "main.py", line 34, in helper.exec() File "C:\Users\30863\Function-level-Vulnerability-Detection-master\src\helper.py", line 252, in exec model_func = elmo_network.build_elmo_network(GPU_flag) File "C:\Users\30863\Function-level-Vulnerability-Detection-master\src\models\elmo_network.py", line 43, in build_elmo_network elmo_embedding = Lambda(self.make_elmo_embedding, output_shape=(None, 1024))(elmo_input) File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\keras\engine\base_layer.py", line 457, in call output = self.call(inputs, kwargs) File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\keras\layers\core.py", line 687, in call return self.function(inputs, arguments) File "C:\Users\30863\Function-level-Vulnerability-Detection-master\src\models\elmo_network.py", line 35, in make_elmo_embedding elmo_model = hub.Module("https://tfhub.dev/google/elmo/2", trainable=True) File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\tensorflow_hub\module.py", line 157, in init self._spec = as_module_spec(spec) File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\tensorflow_hub\module.py", line 30, in as_module_spec return load_module_spec(spec) File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\tensorflow_hub\module.py", line 65, in load_module_spec return registry.loader(path) File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\tensorflow_hub\registry.py", line 51, in call return impl(*args, *kwargs) File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\tensorflow_hub\native_module.py", line 139, in call module_def_proto = self._get_module_def_proto(path) File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\tensorflow_hub\native_module.py", line 130, in _get_module_def_proto module_def_proto.ParseFromString(f.read()) File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\tensorflow_core\python\lib\io\file_io.py", line 122, in read self._preread_check() File "C:\Users\30863\Anaconda3\envs\myenv\lib\site-packages\tensorflow_core\python\lib\io\file_io.py", line 84, in _preread_check compat.as_bytes(self.__name), 1024 512) tensorflow.python.framework.errors_impl.NotFoundError: NewRandomAccessFile failed to Create/Open: C:\Users\30863\AppData\Local\Temp\tfhub_modules\9bb74bc86f9caffc8c47dd7b33ec4bb354d9602d\tfhub_module.pb : The system cannot find the file specified. ; No such file or directory