Spaces:
Sleeping
Sleeping
File size: 1,181 Bytes
b0b2103 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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 |