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

error message ['function' object has no attribute 'Model'] #2

Open
Roboxkin opened this issue May 7, 2024 · 14 comments
Open

error message ['function' object has no attribute 'Model'] #2

Roboxkin opened this issue May 7, 2024 · 14 comments

Comments

@Roboxkin
Copy link

Roboxkin commented May 7, 2024

Hello!
Please help me start training

All the actions I've taken:

  1. Created a new project (ocr_service) in pycharm with a virtual environment

  2. Cloned the project (git clone https://github.com/Azazel0203/ocr_captcha.git)

  3. cd ocr_captcha

  4. pip install -r requirements.txt

  5. Added six new characters "+", "-", "*", "!", "@", "." to the file "artifact/unique_char.csv", "artifact/char_to_num.json", "artifact/num_to_char.json"

  6. In the file "artifact/char_to_num.json" and "artifact/num_to_char.json" corrected "vocabulary_size": 32 to "vocabulary_size": 38

unique_char.csv file:
Screenshot

This is how I have my files now "artifact/char_to_num.json" and "artifact/num_to_char.json"

{"config": {"name": "string_lookup_1", "trainable": true, "dtype": "float32", "invert": true, "max_tokens": null, "num_oov_indices": 1, "oov_token": "[UNK]", "mask_token": null, "output_mode": "int", "sparse": false, "pad_to_max_tokens": false, "idf_weights": null, "vocabulary": ["[UNK]", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "+", "-", "*", "!", "@", "."], "vocabulary_size": 38, "encoding": "utf-8"}, "weights": []}
  1. Created a train folder in the {project name}/ocr captcha directory

  2. Added the file "labels.csv" to the train folder
    Screenshot

  3. Created an images folder in the train directory and placed 93 pictures in it
    Screenshot

  4. In the file "data_ingestion.py" I corrected the paths and the cycle
    Screenshot

  5. Manually added the necessary data to the files (I don't know how correct this is) "raw_img_path.csv", "raw_labels.csv", "test_x.csv", "test_y.csv", "train_x.csv", "train_y.csv"

  6. In the file "model_trainer.py" I changed the line with the sizes of the pictures
    Screenshot_1

  7. I run the file "data_ingestion.py", there are no errors

  8. I run the file "model_trainer.py" and get errors

D:\ocr_service\.venv\Scripts\python.exe D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py 
2024-05-07 09:25:38.677735: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-07 09:25:39.712543: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-07 09:25:41.673057: 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 "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 82, in initate_model_training
    model = build_model(self.img_width, self.img_height, char_to_num) 
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\utils\utils.py", line 178, in build_model
    model = keras.models.Model(
AttributeError: 'function' object has no attribute 'Model'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 129, in <module>
    model_path = trainer.initate_model_training(train_path_x, train_path_y, test_path_x, test_path_y, unique_chars)
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 119, in initate_model_training
    raise customexception(e, sys)
ocr_captcha.src.ocr_captcha.exception.exception.customexception: Error occured in python script | 
 name [D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py] 
 line number [82] 
 error message ['function' object has no attribute 'Model']

Process finished with exit code 1
  1. In the file "model_trainer.py" line 15 is highlighted as an error
    Screenshot_2

  2. You have written "inference/: Module for making predictions on new images.", there is no such file

What am I doing wrong?
Please help me start training and then test the model.
I would be grateful for any help!
Thank you

Python version 3.10.11
Windows 11 x64
no GPU

@Azazel0203
Copy link
Owner

Azazel0203 commented May 7, 2024

Hello! Please help me start training

All the actions I've taken:

  1. Created a new project (ocr_service) in pycharm with a virtual environment
  2. Cloned the project (git clone https://github.com/Azazel0203/ocr_captcha.git)
  3. cd ocr_captcha
  4. pip install -r requirements.txt
  5. Added six new characters "+", "-", "*", "!", "@", "." to the file "artifact/unique_char.csv", "artifact/char_to_num.json", "artifact/num_to_char.json"
  6. In the file "artifact/char_to_num.json" and "artifact/num_to_char.json" corrected "vocabulary_size": 32 to "vocabulary_size": 38

unique_char.csv file: Screenshot

This is how I have my files now "artifact/char_to_num.json" and "artifact/num_to_char.json"

{"config": {"name": "string_lookup_1", "trainable": true, "dtype": "float32", "invert": true, "max_tokens": null, "num_oov_indices": 1, "oov_token": "[UNK]", "mask_token": null, "output_mode": "int", "sparse": false, "pad_to_max_tokens": false, "idf_weights": null, "vocabulary": ["[UNK]", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "+", "-", "*", "!", "@", "."], "vocabulary_size": 38, "encoding": "utf-8"}, "weights": []}
  1. Created a train folder in the {project name}/ocr captcha directory
  2. Added the file "labels.csv" to the train folder
    Screenshot
  3. Created an images folder in the train directory and placed 93 pictures in it
    Screenshot
  4. In the file "data_ingestion.py" I corrected the paths and the cycle
    Screenshot
  5. Manually added the necessary data to the files (I don't know how correct this is) "raw_img_path.csv", "raw_labels.csv", "test_x.csv", "test_y.csv", "train_x.csv", "train_y.csv"
  6. In the file "model_trainer.py" I changed the line with the sizes of the pictures
    Screenshot_1
  7. I run the file "data_ingestion.py", there are no errors
  8. I run the file "model_trainer.py" and get errors
D:\ocr_service\.venv\Scripts\python.exe D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py 
2024-05-07 09:25:38.677735: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-07 09:25:39.712543: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-07 09:25:41.673057: 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 "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 82, in initate_model_training
    model = build_model(self.img_width, self.img_height, char_to_num) 
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\utils\utils.py", line 178, in build_model
    model = keras.models.Model(
AttributeError: 'function' object has no attribute 'Model'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 129, in <module>
    model_path = trainer.initate_model_training(train_path_x, train_path_y, test_path_x, test_path_y, unique_chars)
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 119, in initate_model_training
    raise customexception(e, sys)
ocr_captcha.src.ocr_captcha.exception.exception.customexception: Error occured in python script | 
 name [D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py] 
 line number [82] 
 error message ['function' object has no attribute 'Model']

Process finished with exit code 1
  1. In the file "model_trainer.py" line 15 is highlighted as an error
    Screenshot_2
  2. You have written "inference/: Module for making predictions on new images.", there is no such file

What am I doing wrong? Please help me start training and then test the model. I would be grateful for any help! Thank you

Python version 3.10.11 Windows 11 x64 no GPU

You shouldn't manually change the json files in the artifacts. The data-ingestion part does it for you.
Also you shouldn't be changing the paths. Only path you should update is the path to the main data (training and testing data).
Rest all the things are supposed to run as it is.

Also delete the artifact folder and then create a new folder name artifact to proceed.
As your data is of different kind, You would need to create different artifacts.

@Roboxkin
Copy link
Author

Roboxkin commented May 8, 2024

Thank you very much for the answer!
deleted the artifact folder, then ran the data_ingestion.py file, after which the artifact folder was created with all the files.
Then I ran the model_trainer.py file and got the error

D:\ocr_service\.venv\Scripts\python.exe D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py 
2024-05-08 04:14:12.360207: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-08 04:14:13.353849: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-08 04:14:15.140182: 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 "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 82, in initate_model_training
    model = build_model(self.img_width, self.img_height, char_to_num) 
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\utils\utils.py", line 178, in build_model
    model = keras.models.Model(
AttributeError: 'function' object has no attribute 'Model'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 129, in <module>
    model_path = trainer.initate_model_training(train_path_x, train_path_y, test_path_x, test_path_y, unique_chars)
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 119, in initate_model_training
    raise customexception(e, sys)
ocr_captcha.src.ocr_captcha.exception.exception.customexception: Error occured in python script | 
 name [D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py] 
 line number [82] 
 error message ['function' object has no attribute 'Model']

Process finished with exit code 1

@Azazel0203
Copy link
Owner

Thank you very much for the answer!
deleted the artifact folder, then ran the data_ingestion.py file, after which the artifact folder was created with all the files.
Then I ran the model_trainer.py file and got the error

D:\ocr_service\.venv\Scripts\python.exe D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py 
2024-05-08 04:14:12.360207: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-08 04:14:13.353849: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-08 04:14:15.140182: 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 "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 82, in initate_model_training
    model = build_model(self.img_width, self.img_height, char_to_num) 
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\utils\utils.py", line 178, in build_model
    model = keras.models.Model(
AttributeError: 'function' object has no attribute 'Model'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 129, in <module>
    model_path = trainer.initate_model_training(train_path_x, train_path_y, test_path_x, test_path_y, unique_chars)
  File "D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py", line 119, in initate_model_training
    raise customexception(e, sys)
ocr_captcha.src.ocr_captcha.exception.exception.customexception: Error occured in python script | 
 name [D:\ocr_service\ocr_captcha\src\ocr_captcha\components\model_trainer.py] 
 line number [82] 
 error message ['function' object has no attribute 'Model']

Process finished with exit code 1

Install the requirements_dev and try.

@Roboxkin
Copy link
Author

Roboxkin commented May 8, 2024

I installed it, but it didn't help
Screenshot

@Azazel0203
Copy link
Owner

I installed it, but it didn't help Screenshot

I am a bit busy right now...i will check the code again and get back to you by tomorrow.

@Roboxkin
Copy link
Author

Roboxkin commented May 8, 2024

Я установил, но это не помоглоСкриншот

Я сейчас немного занят... я проверю код еще раз и свяжусь с вами завтра.

Thanks a lot

@Roboxkin
Copy link
Author

I understand that the project can be deleted.

@Azazel0203
Copy link
Owner

I understand that the project can be deleted.

What do u mean?

I am still held back with my college..i am gonna check the code when i am free.

@Roboxkin
Copy link
Author

I mean, you promised to contact me the next day, but you didn't do anything.
I understand that you don't have to, but you promised.
Think for yourself, what should I think in such a situation?
As a user, I received errors that I am not able to fix myself.
You, as the author, can correct them, you promised to look and correct them if possible, you promise to look into it and report it the next day, several days have passed and you are silent.
What should you think in such a situation?

@Azazel0203
Copy link
Owner

I mean, you promised to contact me the next day, but you didn't do anything.
I understand that you don't have to, but you promised.
Think for yourself, what should I think in such a situation?
As a user, I received errors that I am not able to fix myself.
You, as the author, can correct them, you promised to look and correct them if possible, you promise to look into it and report it the next day, several days have passed and you are silent.
What should you think in such a situation?

Well i have been busy with my college exams..
I will look into it today... Don't worry

Abe also it's not that you can't fix the error... You can always make a PR to fix the error.

@Roboxkin
Copy link
Author

I mean, you promised to contact me the next day, but you didn't do anything.
I understand that you don't have to, but you promised.
Think for yourself, what should I think in such a situation?
As a user, I received errors that I am not able to fix myself.
You, as the author, can correct them, you promised to look and correct them if possible, you promise to look into it and report it the next day, several days have passed and you are silent.
What should you think in such a situation?

Well i have been busy with my college exams.. I will look into it today... Don't worry

Abe also it's not that you can't fix the error... You can always make a PR to fix the error.

Don't think anything bad, I'm writing through Google translator.
I'm not a professional programmer, I'm just learning.
Thanks a lot

@Azazel0203
Copy link
Owner

I mean, you promised to contact me the next day, but you didn't do anything.
I understand that you don't have to, but you promised.
Think for yourself, what should I think in such a situation?
As a user, I received errors that I am not able to fix myself.
You, as the author, can correct them, you promised to look and correct them if possible, you promise to look into it and report it the next day, several days have passed and you are silent.
What should you think in such a situation?

Well i have been busy with my college exams.. I will look into it today... Don't worry
Abe also it's not that you can't fix the error... You can always make a PR to fix the error.

Don't think anything bad, I'm writing through Google translator. I'm not a professional programmer, I'm just learning. Thanks a lot

ohh so whats ur native language

Also I tried running it on my local...and its running fine
image

So i cant recreate the error.
Tell me a way I can contact You properly to sort this problem of yours...Do you have discord?

@Roboxkin
Copy link
Author

My native Russian language)
Can I ask you to check my project?
It contains everything that I wrote to you and all the pictures.
It’s possible, of course, that you have something installed that I don’t, because it can’t be that it works for one person, but not for another.

The project turned out to be 38mb, git does not allow more than 25mb, I had to upload an exchanger to the file
Screenshot

https://transfiles.ru/h9sg3

@Roboxkin
Copy link
Author

My discord name Robox

Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants