Spaces:
Runtime error
Runtime error
| import tensorflow as tf | |
| from tensorflow.keras import layers | |
| import cv2 | |
| import numpy as np | |
| def create_model(): | |
| baseModel = tf.keras.applications.efficientnet.EfficientNetB0(include_top=False, weights='imagenet') | |
| baseModel.trainable = False | |
| inputs = layers.Input(shape=(224, 224, 3), name="input_layer") | |
| x = baseModel(inputs) | |
| x = layers.AveragePooling2D()(x) | |
| x = layers.Flatten(name='Flatten')(x) | |
| x = layers.Dense(units=128, activation='relu')(x) | |
| x = layers.Dropout(rate=0.5)(x) | |
| outputs = layers.Dense(units=1, activation='sigmoid')(x) | |
| model = tf.keras.Model(inputs, outputs) | |
| initial_learning_rate = 0.001 | |
| model.compile(loss='binary_crossentropy', | |
| optimizer=tf.keras.optimizers.Adam(learning_rate=initial_learning_rate), | |
| metrics = ['AUC']) | |
| return model | |
| def get_optimal_font_scale(text, width): | |
| for scale in np.arange(1,0.1,-0.2): | |
| scale = round(scale,2) | |
| textSize = cv2.getTextSize(text, fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=scale, thickness=1) | |
| new_width = textSize[0][0] | |
| if (new_width <= width): | |
| return scale | |
| return 0.1 |