Skip to content

Commit

Permalink
feat: Add new theme for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohulan committed Jul 3, 2023
1 parent e715966 commit 4d69afd
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Benchmark/distort_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def distort_image(input_image_path: str, output_image_path: str) -> None:
def main():
"""This script takes an input directory with images of chemical structure depictions, applies a random
rotation (-5° or +5°) as well as shearing (angle drawn from [-0.1, 0.1]) to every input image. These
distortions are supposed to imitate the image modifications described by Clevert et al (Img2Mol (preprint))"""
distortions are supposed to imitate the image modifications described by Clevert et al (Img2Mol (preprint))
"""
input_dir = os.path.abspath(sys.argv[1])
output_dir = os.path.abspath(sys.argv[2])
if not os.path.exists(output_dir):
Expand Down
1 change: 0 additions & 1 deletion DECIMER/DECIMER_EfficinetNetV2_Transfomer_Trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ def prepare_for_training(lr_config, encoder_config, transformer_config, verbose=
"""

with strategy.scope():

loss_object = tf.keras.losses.SparseCategoricalCrossentropy(
from_logits=True, reduction=tf.keras.losses.Reduction.NONE
)
Expand Down
1 change: 0 additions & 1 deletion DECIMER/Efficient_Net_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def __init__(
pretrained_weights=None,
scale_factor=0,
):

super(Encoder, self).__init__()

self.image_embedding_dim = image_embedding_dim
Expand Down
12 changes: 6 additions & 6 deletions DECIMER/Repack_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import tensorflow as tf

import pickle
import Transformer_decoder
import Efficient_Net_encoder
import config
import utils
import DECIMER.Efficient_Net_encoder as Efficient_Net_encoder
import DECIMER.Transformer_decoder as Transformer_decoder
import DECIMER.config as config
import DECIMER.utils as utils

print(tf.__version__)

Expand All @@ -16,8 +16,8 @@
tf.config.experimental.set_memory_growth(gpu, True)

# load assets
tokenizer = pickle.load(open("tokenizer_TPU_Stereo.pkl", "rb"))
max_length = pickle.load(open("max_length_TPU_Stereo.pkl", "rb"))
tokenizer = pickle.load(open("tokenizer.pkl", "rb"))
max_length = pickle.load(open("max_length.pkl", "rb"))

# Image parameters
IMG_EMB_DIM = (16, 16, 232)
Expand Down
7 changes: 0 additions & 7 deletions DECIMER/Transformer_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def create_look_ahead_mask(size):


def create_mask(inp, tar):

# Used in the 1st attention block in the decoder.
# It is used to pad and mask future tokens in the input received by
# the decoder.
Expand Down Expand Up @@ -209,7 +208,6 @@ def point_wise_feed_forward_network(d_model, dff):

class TransformerEncoderLayer(tf.keras.layers.Layer):
def __init__(self, d_model, num_heads, dff, dropout_rate=0.1):

super(TransformerEncoderLayer, self).__init__()

self.mha = tf.keras.layers.MultiHeadAttention(
Expand All @@ -225,7 +223,6 @@ def __init__(self, d_model, num_heads, dff, dropout_rate=0.1):
self.dropout2 = tf.keras.layers.Dropout(dropout_rate)

def call(self, x, training, mask=None):

# returns (batch_size, input_seq_len, d_model)
attn_output, _ = self.mha(x, x, x, mask, return_attention_scores=True)

Expand All @@ -250,7 +247,6 @@ def call(self, x, training, mask=None):

class TransformerDecoderLayer(tf.keras.layers.Layer):
def __init__(self, d_model, num_heads, dff, dropout_rate=0.1):

super(TransformerDecoderLayer, self).__init__()

# WE COULD USE A CUSTOM DEFINED MHA MODEL BUT WE WILL USE TFA INSTEAD
Expand All @@ -276,7 +272,6 @@ def __init__(self, d_model, num_heads, dff, dropout_rate=0.1):

# enc_output.shape == (batch_size, input_seq_len, d_model)
def call(self, x, enc_output, training, look_ahead_mask=None, padding_mask=None):

attn1, attn_weights_block1 = self.mha1(x, x, x, look_ahead_mask)
attn1 = self.dropout1(attn1, training=training)

Expand Down Expand Up @@ -370,7 +365,6 @@ def __init__(
self.dropout = tf.keras.layers.Dropout(dropout_rate)

def call(self, x, enc_output, training, look_ahead_mask=None, padding_mask=None):

seq_len = tf.shape(x)[1]
attention_weights = {}

Expand Down Expand Up @@ -405,7 +399,6 @@ def __init__(
pe_target,
dropout_rate=0.1,
):

super(Transformer, self).__init__()

self.t_encoder = TransformerEncoder(
Expand Down
2 changes: 0 additions & 2 deletions DECIMER/Utils/Create_TFrecord_From_pickles.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def _bytes_feature(value):
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))

def get_train_tfrecord(num_shards, train_captions, img_name_vector, file_index):

print("Total number of TFrecords: ", num_shards, flush=True)

for i in range(num_shards):
Expand All @@ -57,7 +56,6 @@ def get_train_tfrecord(num_shards, train_captions, img_name_vector, file_index):
writer = tf.io.TFRecordWriter(tfrecord_name)
counter = 0
for j in range(len(sub_split_img_id)):

# print(decoded_image.shape)
caption_ = sub_split_cap_train[j]
# image_id_ = sub_split_img_id[counter]
Expand Down
2 changes: 0 additions & 2 deletions DECIMER/Utils/Create_image_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


def main():

Smiles_Path = "Path_to_file"
# Images_Path = "Train_Images/"

Expand Down Expand Up @@ -61,7 +60,6 @@ def main():


def data_loader(Smiles_Path):

# read the Captions file
with open(Smiles_Path, "r") as txt_file:
smiles = txt_file.read()
Expand Down
20 changes: 12 additions & 8 deletions DECIMER/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,25 @@ def download_trained_weights(model_url: str, model_path: str, verbose=1):
"""This function downloads the trained models and tokenizers to a default location.
After downloading the zipped file the function unzips the file automatically.
If the model exists on the default location this function will not work.
Args:
model_url (str): trained model url for downloading.
model_path (str): model default path to download.
Returns:
downloaded model.
path (str): downloaded model.
"""
# Download trained models
if verbose > 0:
print("Downloading trained model to " + str(model_path))
model_path = pystow.ensure("DECIMER-V2", url=model_url)
print(model_path)
model_path = pystow.ensure("DECIMER-V2", url=model_url)
if verbose > 0:
print(model_path)
print("... done downloading trained model!")
with zipfile.ZipFile(model_path.as_posix(), "r") as zip_ref:
zip_ref.extractall(model_path.parent.as_posix())
# Delete zipfile after downloading
if Path(model_path).exists():
Path(model_path).unlink()

with zipfile.ZipFile(model_path.as_posix(), "r") as zip_ref:
zip_ref.extractall(model_path.parent.as_posix())

# Delete zipfile after downloading
if Path(model_path).exists():
Path(model_path).unlink()
2 changes: 1 addition & 1 deletion DECIMER/efficientnetv2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def get_ckpt_var_map(
if not var_map or len(var_map) < 5:
raise ValueError(f"var_map={var_map} is almost empty, please check logs.")

for (k, v) in var_map.items():
for k, v in var_map.items():
logging.log_first_n(logging.INFO, f"Init {v.op.name} from ckpt var {k}", 10)

return var_map
35 changes: 28 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

# -- Project information -----------------------------------------------------

project = "DECIMER"
copyright = "2022, Kohulan"
author = "Kohulan"
project = "DECIMER-Image_Transformer"
copyright = "2023, Kohulan Rajan"
author = "Kohulan Rajan"

# The full version, including alpha/beta/rc tags
release = "2.0.0"
release = "2.3.0"


# -- General configuration ---------------------------------------------------
Expand All @@ -34,7 +34,6 @@
"sphinx.ext.autodoc",
"sphinx_autodoc_typehints",
"sphinx.ext.autosummary",
"sphinx_rtd_theme",
"nbsphinx",
"sphinx.ext.mathjax",
"sphinx.ext.githubpages",
Expand Down Expand Up @@ -67,13 +66,35 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"
html_theme = "sphinx_material"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
# Material theme options (see theme.conf for more information)
html_theme_options = {
# Set the name of the project to appear in the navigation.
"nav_title": "DECIMER-Image_Transformer",
# Specify a base_url used to generate sitemap.xml. If not
# specified, then no sitemap will be built.
"base_url": "https://github.com/Kohulan/DECIMER-Image_Transformer",
# Set the color and the accent color
"color_primary": "blue",
"color_accent": "light-blue",
"html_minify": True,
"css_minify": True,
"logo_icon": "&#xe869",
# Set the repo location to get a badge with stats
"repo_url": "https://github.com/Kohulan/DECIMER-Image_Transformer/",
"repo_name": "DECIMER-Image_Transformer",
# Visible levels of the global TOC; -1 means unlimited
"globaltoc_depth": 3,
# If False, expand all TOC entries
"globaltoc_collapse": False,
# If True, show hidden TOC entries
"globaltoc_includehidden": False,
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
nbsphinx
sphinx-autodoc-typehints
sphinx_rtd_theme
furo
sphinx_material
numpy>=1.19
tensorflow>=2.6.3
opencv-python
Expand Down

0 comments on commit 4d69afd

Please sign in to comment.