sharktide commited on
Commit
2065c50
·
verified ·
1 Parent(s): 5f110cd

Create custom_objects.py

Browse files
Files changed (1) hide show
  1. custom_objects.py +31 -0
custom_objects.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tensorflow.keras.saving import register_keras_serializable
2
+ from tensorflow.keras import layers, models, backend as K
3
+ import tensorflow as tf
4
+
5
+ @register_keras_serializable()
6
+ def drainage_penalty(inputs):
7
+ dd = inputs[:, 2]
8
+ return (1.0 - 0.4 * tf.sigmoid((dd - 3.5) * 2))[:, None]
9
+
10
+ @register_keras_serializable()
11
+ def convergence_suppressor(inputs):
12
+ ci = inputs[:, 4]
13
+ return (1.0 + 0.3 * tf.sigmoid((ci - 0.5) * 8))[:, None]
14
+
15
+ @register_keras_serializable()
16
+ def intensity_slope_amplifier(inputs):
17
+ rainfall_intensity = inputs[:, 0]
18
+ slope = inputs[:, 1]
19
+ runoff_boost = tf.sigmoid((rainfall_intensity - 75) * 0.08)
20
+ slope_boost = tf.sigmoid((slope - 10) * 0.05)
21
+ return (1.0 + 0.35 * runoff_boost * slope_boost)[:, None]
22
+
23
+ def clip_modulation(x):
24
+ return tf.clip_by_value(x, 0.7, 1.3)
25
+
26
+ CUSTOM_OBJECTS = {
27
+ 'drainage_penalty': drainage_penalty,
28
+ 'intensity_slope_amplifier': intensity_slope_amplifier,
29
+ 'convergence_suppressor': convergence_suppressor,
30
+ 'clip_modulation': clip_modulation
31
+ }