Kohulan / DECIMER-Image_Transformer

DECIMER Image Transformer is a deep-learning-based tool designed for automated recognition of chemical structure images. Leveraging transformer architectures, the model converts chemical images into SMILES strings, enabling the digitization of chemical data from scanned documents, literature, and patents.
MIT License
214 stars 52 forks source link

Training DECIMER on a new dataset with GPU. #41

Closed lucas-morin closed 1 year ago

lucas-morin commented 1 year ago

Hello, Is it possible to train DECIMER on a new dataset consisting of pairs of images and SMILES, and without having access to TPUs? Best, Lucas

Kohulan commented 1 year ago

Hi @lucasmorin222 ,

In principle, you can. But the current training scripts are written to be trained on TPUs, You could use the MirroredStrategy instead of the TPU strategy to train on GPU.

Please remove these lines from the training script

tpu = tf.distribute.cluster_resolver.TPUClusterResolver(tpu="node-name")
print("Running on TPU ", tpu.master())

tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
strategy = tf.distribute.TPUStrategy(tpu)

and replace it with the following:

strategy = tf.distribute.MirroredStrategy(["GPU:0", "GPU:1"])

You can still use TFRecords to train on GPUs so no need to change anything there.

Regards, Kohulan

lucas-morin commented 1 year ago

Thanks, it worked.

I tokenized SMILES using the tokenizer stored in Zenodo:

DECIMER_512_Model_finetuned/assets/tokenizer_SMILES.pkl DECIMER_512_Model_finetuned/assets/max_length.pkl

Thanks for you help! Regards, Lucas