#๐Ÿ”’ Tensor flow NoneType error

114 messages ยท Page 1 of 1 (latest)

golden ironBOT
#

@shell oxide

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

shell oxide
#

Hello everyone, im trying to train a model using tensorflow and i keep getting this error AttributeError: 'NoneType' object has no attribute 'dtype' and i can't figure out why it's happening even though i added lots of debugging statements in my code to attempt to track what's giving None before passing it to tensorflow but it's still there and im kinda beat, it's been hours im trying to diagnose this and no luck, id appreciate if anyone can give me ideas on what could be causing this:
my code currently:
https://paste.pythondiscord.com/SRPA

#

Tensorflow NoneType error

real flicker
#

Your set up seems to be the issue

shell oxide
#

how?

real flicker
#

The functionality seems to be incorrect for each function you intend this for

shell oxide
#

the intention is to convert pdf to latex

#

so im training a model with existing pdfs and latex

#

i run ocr using ocrmypdf then extract the text with pdfplumber from the searchable pdf

#

and link them with their corresponding latex

#

idk is there something im doing wrong?

real flicker
#

What kind of pdfs
Bank records, node codes, source codes for smart contracts, mining

shell oxide
#

math

#

specific math exams too

real flicker
#

Can you give me a breakdown of what you want the code to do precisely...you seem to be adding the wrong commands

shell oxide
#

for this specific code i want to train it on how to recognize ocr text and convert it to latex, by feeding it a bunch of pdfs that have i done ocr on them and correspond them with their latex

#

all in 1 json file

#

fed to t5-base

#

it starts fine at first but then it just errors midway

#

lemme show u

real flicker
#

You can't use one json file
Did you create a contract you're trying to call from?
Or just want to calculate the earnings, future investment plans.....there's a lot to it

shell oxide
#

none of that, i just want to convert a specific format of exams in my country here to latex

#

im using a very specific dataset

real flicker
#

What country?

shell oxide
#

Tunisia

#

The primary goal is to convert OCR processed text from math exams in pdf format to latex format. this involves training a model using existing pdf and latex pairs

real flicker
#

Hold on a sec

real flicker
#

Hello

shell oxide
#

Hi

#

I'm here @real flicker

real flicker
#

Uninitialized variables: Make sure that all variables are initialized before passing them to the compile() method. Check if you've assigned values to optimizer, loss, and metrics before compiling the model.
Incorrectly defined variables: Double-check that the variables are correctly defined and have the expected types. For example, make sure that optimizer is a string or a TensorFlow optimizer object, and not a None value.
Model not built correctly: Ensure that you've built your model correctly using the Sequential API or the Keras functional API. If your model is not built correctly, it won't have a compile() method.
To debug this further, I recommend adding more print statements to track the values of these variables before passing them to the compile() method.

#

print(optimizer)
print(loss)
print(metrics)
print(type(optimizer))
print(type(loss))
print(type(metrics))

shell oxide
#

alright give me a second let me do that

real flicker
#

Alright

shell oxide
#

All OCR-LaTeX pairs are valid.

All PyTorch model weights were used when initializing TFT5ForConditionalGeneration.

All the weights of TFT5ForConditionalGeneration were initialized from the PyTorch model.
If your task is similar to the task the model of the checkpoint was trained on, you can already use TFT5ForConditionalGeneration for predictions without further training.
Optimizer: <tf_keras.src.optimizers.adam.Adam object at 0x0000028307F599A0>
Debugging information before model compile:
Optimizer: <tf_keras.src.optimizers.adam.Adam object at 0x0000028307F599A0>
Loss: <bound method TFPreTrainedModel.compute_loss of <transformers.models.t5.modeling_tf_t5.TFT5ForConditionalGeneration object at 0x00000283792C54F0>>
Type of optimizer: <class 'tf_keras.src.optimizers.adam.Adam'>
Type of loss: <class 'method'>

okay i suspect it's still the same problem but i have suspicion why it could be happening

#

im suspecting it's the optimizer

#

for it to work i had to set this in env os.environ['TF_USE_LEGACY_KERAS'] = '1'

#

without it ill just get this error: ValueError: Could not interpret optimizer identifier: <keras.src.optimizers.adam.Adam object at 0x0000021E6E5A1400>

real flicker
#

Is this a wallet address

shell oxide
#

no it's not

#

if u mean a crypto address

#

ok im just gonna use another optimizer see what happens

#

RMSprop should do the job

real flicker
#

Do you have good RPC

real flicker
shell oxide
#

i seem to be getting the same error:

ValueError: Could not interpret optimizer identifier: <keras.src.optimizers.rmsprop.RMSprop object at 0x0000019EAAA1A480>

#

something is wrong with tensorflow

#

i gotta figure it out

real flicker
#

You don't own the source code for this right?

shell oxide
#

i made this lol

real flicker
#

Let me try and understand this more

shell oxide
#

you have a pdf

#

an image pdf for example

#

u can't edit

#

you read it using already trained ocr software

#

then that text, we need it to be converted to latex

#

so to do that, we get a bunch of pdfs that have been read with the same ocr software we gonna use later for production

#

and pair with it's corresponding, correct latex

#

and train an open weight model like t5 to be able to recognize and predict more of that text

#

the logic is simple, coding is what's annoying

real flicker
#

Which ocr did you use again

shell oxide
#

the one im gonna be using later is a pretrained model that i've trained for a 3 months now

#

it can read better

#

but this should work too with test dataset im using

real flicker
#

Whats the name

shell oxide
#

OCRmyPDF

real flicker
#

Did you tru TESSERACT OCR engine

shell oxide
#

ocrmypdf already uses tesseract

#

so yes

shell oxide
#

production of a software that can convert exams to latex

#

lots of exams in here are outdated so converting them to latex

#

will modernize them

#

since latex is best with math

real flicker
shell oxide
#

you mean google vision api?

#

that one costs money

#

just like mathpix

#

just like azure

real flicker
#

I think that's the issue

shell oxide
#

my goal is to have full control over the model

#

it's why i don't wanna use api's

real flicker
#

Nothing seems to be wrong woth the code. I think you need a more accurate OCR

real flicker
#

So your model will not only be totally controlled by you but also accurate and up to date.

#

Due to machine learning

shell oxide
#

any guide on how i could use azure

#

for this

#

i need to first test lots of things

real flicker
#

You can test with azure

#

And run wirh azure
Its only to make it easy

real flicker
shell oxide
#

Rn the problem isn't with ocr but this little part here, for some reason whatever optimizer i use, i get the same error


from tensorflow.keras.optimizers import RMSprop
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint

 (....)
 optimizer = tf.keras.optimizers.RMSprop(learning_rate=5e-5)
 print(f"Optimizer: {optimizer}")

 print("Debugging information before model compile:")
 print("Optimizer:", optimizer)
 print("Loss:", model.compute_loss)
 print("Type of optimizer:", type(optimizer))
 print("Type of loss:", type(model.compute_loss))
 
 model.compile(optimizer=optimizer, loss=model.compute_loss)
 print("Model compiled successfully.")
 (...)

ValueError: Could not interpret optimizer identifier: <keras.src.optimizers.rmsprop.RMSprop object at 0x00000219F47324B0>

#

am i doing something wrong

shell oxide
real flicker
#

Well you're not

#

Its just the accuracy that matters

shell oxide
#

it doesn't compile because of that optimizer error

real flicker
#

So... Still think its there?

shell oxide
#

yes because i just fixed it

real flicker
#

Nice

#

How?

shell oxide
#

i had to simply check for gradients before applying them

#

works now

#

thanks anyway

tame basalt
golden ironBOT
#

:incoming_envelope: :ok_hand: applied warning to @real flicker.

tame basalt
golden ironBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.