nanduriprudhvi commited on
Commit
9137f09
·
verified ·
1 Parent(s): d8b1c89

Update convlstm.py

Browse files
Files changed (1) hide show
  1. convlstm.py +228 -228
convlstm.py CHANGED
@@ -1,229 +1,229 @@
1
- import tensorflow as tf
2
- from tensorflow.keras import layers, models # type: ignore
3
- import numpy as np
4
-
5
- # Define the ConvGRU2DLayer (same as before)
6
-
7
- def build_3d_conv_lstm_model(input_shape=(8, 95, 95, 2), batch_size=16):
8
- """
9
- Builds a 3D ConvLSTM model with Conv3D layers and MaxPooling3D layers.
10
-
11
- Parameters:
12
- - input_shape: Shape of the input tensor (time_steps, height, width, channels).
13
- - batch_size: Batch size for the model.
14
-
15
- Returns:
16
- - model: The compiled Keras model.
17
- """
18
- # Input tensor
19
- input_tensor = layers.Input(shape=input_shape)
20
-
21
- # First ConvLSTM2D block with Conv3D
22
- x = layers.ConvLSTM2D(filters=32, kernel_size=(3, 3), padding='same', return_sequences=True)(input_tensor)
23
- x = layers.Conv3D(filters=32, kernel_size=(3, 3, 3), padding='same', activation='relu')(x)
24
- x = layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(4, 3, 3), padding='same')(x)
25
-
26
- # Second ConvLSTM2D block with Conv3D
27
- x = layers.ConvLSTM2D(filters=64, kernel_size=(3, 3), padding='same', return_sequences=True)(x)
28
- x = layers.Conv3D(filters=64, kernel_size=(3, 3, 3), padding='same', activation='relu')(x)
29
- x = layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(4, 3, 3), padding='same')(x)
30
-
31
- # Third ConvLSTM2D block with Conv3D
32
- x = layers.ConvLSTM2D(filters=128, kernel_size=(3, 3), padding='same', return_sequences=True)(x)
33
- x = layers.Conv3D(filters=128, kernel_size=(3, 3, 3), padding='same', activation='relu')(x)
34
- x = layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2), padding='same')(x)
35
-
36
- # Flatten the output before passing to the fully connected layers
37
- x = layers.Flatten()(x)
38
-
39
- # Create the final model
40
- model = models.Model(inputs=input_tensor, outputs=x)
41
-
42
- return model
43
-
44
- def radial_structure_subnet(input_shape):
45
- """
46
- Creates the subnet for extracting TC radial structure features using a five-branch CNN design with 2D convolutions.
47
-
48
- Parameters:
49
- - input_shape: tuple, shape of the input data (e.g., (95, 95, 3))
50
-
51
- Returns:
52
- - model: tf.keras.Model, the radial structure subnet model
53
- """
54
-
55
- input_tensor = layers.Input(shape=input_shape)
56
-
57
- # Divide input data into four quadrants (NW, NE, SW, SE)
58
- # Assuming the input shape is (batch_size, height, width, channels)
59
-
60
- # Quadrant extraction - using slicing to separate quadrants
61
- nw_quadrant = input_tensor[:, :input_shape[0]//2, :input_shape[1]//2, :]
62
- ne_quadrant = input_tensor[:, :input_shape[0]//2, input_shape[1]//2:, :]
63
- sw_quadrant = input_tensor[:, input_shape[0]//2:, :input_shape[1]//2, :]
64
- se_quadrant = input_tensor[:, input_shape[0]//2:, input_shape[1]//2:, :]
65
-
66
-
67
- target_height = max(input_shape[0]//2, input_shape[0] - input_shape[0]//2) # 48
68
- target_width = max(input_shape[1]//2, input_shape[1] - input_shape[1]//2) # 48
69
-
70
- # Padding the quadrants to match the target size (48, 48)
71
- nw_quadrant = layers.ZeroPadding2D(padding=((0, target_height - nw_quadrant.shape[1]),
72
- (0, target_width - nw_quadrant.shape[2])))(nw_quadrant)
73
- ne_quadrant = layers.ZeroPadding2D(padding=((0, target_height - ne_quadrant.shape[1]),
74
- (0, target_width - ne_quadrant.shape[2])))(ne_quadrant)
75
- sw_quadrant = layers.ZeroPadding2D(padding=((0, target_height - sw_quadrant.shape[1]),
76
- (0, target_width - sw_quadrant.shape[2])))(sw_quadrant)
77
- se_quadrant = layers.ZeroPadding2D(padding=((0, target_height - se_quadrant.shape[1]),
78
- (0, target_width - se_quadrant.shape[2])))(se_quadrant)
79
-
80
- print(nw_quadrant.shape)
81
- print(ne_quadrant.shape)
82
- print(sw_quadrant.shape)
83
- print(se_quadrant.shape)
84
- # Main branch (processing the entire structure)
85
- main_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(input_tensor)
86
- y=layers.MaxPool2D()(main_branch)
87
-
88
- y = layers.ZeroPadding2D(padding=((0, target_height - y.shape[1]),
89
- (0, target_width - y.shape[2])))(y)
90
- # Side branches (processing the individual quadrants)
91
- nw_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(nw_quadrant)
92
- ne_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(ne_quadrant)
93
- sw_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(sw_quadrant)
94
- se_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(se_quadrant)
95
-
96
- # Apply padding to the side branches to match the dimensions of the main branch
97
- # nw_branch = layers.UpSampling2D(size=(2, 2), interpolation='nearest')(nw_branch)
98
- # ne_branch = layers.UpSampling2D(size=(2, 2), interpolation='nearest')(ne_branch)
99
- # sw_branch = layers.UpSampling2D(size=(2, 2), interpolation='nearest')(sw_branch)
100
- # se_branch = layers.UpSampling2D(size=(2, 2), interpolation='nearest')(se_branch)
101
-
102
- # Fusion operations (concatenate the outputs from the main branch and side branches)
103
- fusion = layers.concatenate([y, nw_branch, ne_branch, sw_branch, se_branch], axis=-1)
104
-
105
- # Additional convolution layer to combine the fused features
106
- x = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(fusion)
107
- x=layers.MaxPool2D(pool_size=(2, 2))(x)
108
- # Final dense layer for further processing
109
- nw_branch = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(nw_branch)
110
-
111
- ne_branch = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(ne_branch)
112
- sw_branch = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(sw_branch)
113
- se_branch = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(se_branch)
114
- nw_branch = layers.MaxPool2D(pool_size=(2, 2))(nw_branch)
115
- ne_branch = layers.MaxPool2D(pool_size=(2, 2))(ne_branch)
116
- sw_branch = layers.MaxPool2D(pool_size=(2, 2))(sw_branch)
117
- se_branch = layers.MaxPool2D(pool_size=(2, 2))(se_branch)
118
-
119
- fusion = layers.concatenate([x, nw_branch, ne_branch, sw_branch, se_branch], axis=-1)
120
- x = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(fusion)
121
- x=layers.MaxPool2D(pool_size=(2, 2))(x)
122
-
123
- nw_branch = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(nw_branch)
124
-
125
- ne_branch = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(ne_branch)
126
- sw_branch = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(sw_branch)
127
- se_branch = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(se_branch)
128
- nw_branch = layers.MaxPool2D(pool_size=(2, 2))(nw_branch)
129
- ne_branch = layers.MaxPool2D(pool_size=(2, 2))(ne_branch)
130
- sw_branch = layers.MaxPool2D(pool_size=(2, 2))(sw_branch)
131
- se_branch = layers.MaxPool2D(pool_size=(2, 2))(se_branch)
132
-
133
- fusion = layers.concatenate([x, nw_branch, ne_branch, sw_branch, se_branch], axis=-1)
134
- x = layers.Conv2D(filters=32, kernel_size=(3, 3), activation='relu')(fusion)
135
- x=layers.Conv2D(filters=32, kernel_size=(3, 3), activation=None)(x)
136
- # Create and return the model
137
- x=layers.Flatten()(x)
138
- model = models.Model(inputs=input_tensor, outputs=x)
139
- return model
140
-
141
- # Define input shape (batch_size, height, width, channels)
142
- # input_shape = (95, 95, 8) # Example input shape (95x95 spatial resolution, 3 channels)
143
-
144
- # # Build the model
145
- # model = radial_structure_subnet(input_shape)
146
-
147
- # # Model summary
148
- # model.summary()
149
-
150
- def build_cnn_model(input_shape=(8, 8, 1)):
151
- # Define the input layer
152
- input_tensor = layers.Input(shape=input_shape)
153
-
154
- # Convolutional layer
155
- x = layers.Conv2D(64, (3, 3), padding='same')(input_tensor)
156
- x = layers.BatchNormalization()(x)
157
- x = layers.ReLU()(x)
158
-
159
- # Flatten layer
160
- x = layers.Flatten()(x)
161
-
162
- # Create the model
163
- model = models.Model(inputs=input_tensor, outputs=x)
164
-
165
- return model
166
-
167
- from tensorflow.keras import layers, models, Input # type: ignore
168
-
169
- def build_combined_model():
170
- # Define input shapes
171
- input_shape_3d = (8, 95, 95, 2)
172
- input_shape_radial = (95, 95, 8)
173
- input_shape_cnn = (8, 8, 1)
174
-
175
- input_shape_latitude = (8,)
176
- input_shape_longitude = (8,)
177
- input_shape_other = (9,)
178
-
179
- # Build individual models
180
- model_3d = build_3d_conv_lstm_model(input_shape=input_shape_3d)
181
- model_radial = radial_structure_subnet(input_shape=input_shape_radial)
182
- model_cnn = build_cnn_model(input_shape=input_shape_cnn)
183
-
184
- # Define new inputs
185
- input_latitude = Input(shape=input_shape_latitude ,name="latitude_input")
186
- input_longitude = Input(shape=input_shape_longitude, name="longitude_input")
187
- input_other = Input(shape=input_shape_other, name="other_input")
188
-
189
- # Flatten the additional inputs
190
- flat_latitude = layers.Dense(32,activation='relu')(input_latitude)
191
- flat_longitude = layers.Dense(32,activation='relu')(input_longitude)
192
- flat_other = layers.Dense(64,activation='relu')(input_other)
193
-
194
- # Combine all outputs
195
- combined = layers.concatenate([
196
- model_3d.output,
197
- model_radial.output,
198
- model_cnn.output,
199
- flat_latitude,
200
- flat_longitude,
201
- flat_other
202
- ])
203
-
204
- # Add dense layers for final processing
205
- x = layers.Dense(128, activation='relu')(combined)
206
- x = layers.Dense(1, activation=None)(x)
207
-
208
- # Create the final model
209
- final_model = models.Model(
210
- inputs=[model_3d.input, model_radial.input, model_cnn.input,
211
- input_latitude, input_longitude, input_other ],
212
- outputs=x
213
- )
214
-
215
- return final_model
216
-
217
- import h5py
218
- with h5py.File(r"E:\1MAIN PROJECT\tf_env\lstm3dcnn-model.h5", 'r') as f:
219
- print(f.attrs.get('keras_version'))
220
- print(f.attrs.get('backend'))
221
- print("Model layers:", list(f['model_weights'].keys()))
222
-
223
- model = build_combined_model() # Your original model building function
224
- model.load_weights(r"E:\1MAIN PROJECT\tf_env\lstm3dcnn-model.h5")
225
-
226
-
227
- def predict_lstm(reduced_images_test,hov_m_test,test_vmax_3d,lat_test,lon_test,int_diff_test):
228
- y=model.predict([reduced_images_test,hov_m_test,test_vmax_3d,lat_test,lon_test,int_diff_test ])
229
  return y
 
1
+ import tensorflow as tf
2
+ from tensorflow.keras import layers, models # type: ignore
3
+ import numpy as np
4
+
5
+ # Define the ConvGRU2DLayer (same as before)
6
+
7
+ def build_3d_conv_lstm_model(input_shape=(8, 95, 95, 2), batch_size=16):
8
+ """
9
+ Builds a 3D ConvLSTM model with Conv3D layers and MaxPooling3D layers.
10
+
11
+ Parameters:
12
+ - input_shape: Shape of the input tensor (time_steps, height, width, channels).
13
+ - batch_size: Batch size for the model.
14
+
15
+ Returns:
16
+ - model: The compiled Keras model.
17
+ """
18
+ # Input tensor
19
+ input_tensor = layers.Input(shape=input_shape)
20
+
21
+ # First ConvLSTM2D block with Conv3D
22
+ x = layers.ConvLSTM2D(filters=32, kernel_size=(3, 3), padding='same', return_sequences=True)(input_tensor)
23
+ x = layers.Conv3D(filters=32, kernel_size=(3, 3, 3), padding='same', activation='relu')(x)
24
+ x = layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(4, 3, 3), padding='same')(x)
25
+
26
+ # Second ConvLSTM2D block with Conv3D
27
+ x = layers.ConvLSTM2D(filters=64, kernel_size=(3, 3), padding='same', return_sequences=True)(x)
28
+ x = layers.Conv3D(filters=64, kernel_size=(3, 3, 3), padding='same', activation='relu')(x)
29
+ x = layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(4, 3, 3), padding='same')(x)
30
+
31
+ # Third ConvLSTM2D block with Conv3D
32
+ x = layers.ConvLSTM2D(filters=128, kernel_size=(3, 3), padding='same', return_sequences=True)(x)
33
+ x = layers.Conv3D(filters=128, kernel_size=(3, 3, 3), padding='same', activation='relu')(x)
34
+ x = layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2), padding='same')(x)
35
+
36
+ # Flatten the output before passing to the fully connected layers
37
+ x = layers.Flatten()(x)
38
+
39
+ # Create the final model
40
+ model = models.Model(inputs=input_tensor, outputs=x)
41
+
42
+ return model
43
+
44
+ def radial_structure_subnet(input_shape):
45
+ """
46
+ Creates the subnet for extracting TC radial structure features using a five-branch CNN design with 2D convolutions.
47
+
48
+ Parameters:
49
+ - input_shape: tuple, shape of the input data (e.g., (95, 95, 3))
50
+
51
+ Returns:
52
+ - model: tf.keras.Model, the radial structure subnet model
53
+ """
54
+
55
+ input_tensor = layers.Input(shape=input_shape)
56
+
57
+ # Divide input data into four quadrants (NW, NE, SW, SE)
58
+ # Assuming the input shape is (batch_size, height, width, channels)
59
+
60
+ # Quadrant extraction - using slicing to separate quadrants
61
+ nw_quadrant = input_tensor[:, :input_shape[0]//2, :input_shape[1]//2, :]
62
+ ne_quadrant = input_tensor[:, :input_shape[0]//2, input_shape[1]//2:, :]
63
+ sw_quadrant = input_tensor[:, input_shape[0]//2:, :input_shape[1]//2, :]
64
+ se_quadrant = input_tensor[:, input_shape[0]//2:, input_shape[1]//2:, :]
65
+
66
+
67
+ target_height = max(input_shape[0]//2, input_shape[0] - input_shape[0]//2) # 48
68
+ target_width = max(input_shape[1]//2, input_shape[1] - input_shape[1]//2) # 48
69
+
70
+ # Padding the quadrants to match the target size (48, 48)
71
+ nw_quadrant = layers.ZeroPadding2D(padding=((0, target_height - nw_quadrant.shape[1]),
72
+ (0, target_width - nw_quadrant.shape[2])))(nw_quadrant)
73
+ ne_quadrant = layers.ZeroPadding2D(padding=((0, target_height - ne_quadrant.shape[1]),
74
+ (0, target_width - ne_quadrant.shape[2])))(ne_quadrant)
75
+ sw_quadrant = layers.ZeroPadding2D(padding=((0, target_height - sw_quadrant.shape[1]),
76
+ (0, target_width - sw_quadrant.shape[2])))(sw_quadrant)
77
+ se_quadrant = layers.ZeroPadding2D(padding=((0, target_height - se_quadrant.shape[1]),
78
+ (0, target_width - se_quadrant.shape[2])))(se_quadrant)
79
+
80
+ print(nw_quadrant.shape)
81
+ print(ne_quadrant.shape)
82
+ print(sw_quadrant.shape)
83
+ print(se_quadrant.shape)
84
+ # Main branch (processing the entire structure)
85
+ main_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(input_tensor)
86
+ y=layers.MaxPool2D()(main_branch)
87
+
88
+ y = layers.ZeroPadding2D(padding=((0, target_height - y.shape[1]),
89
+ (0, target_width - y.shape[2])))(y)
90
+ # Side branches (processing the individual quadrants)
91
+ nw_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(nw_quadrant)
92
+ ne_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(ne_quadrant)
93
+ sw_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(sw_quadrant)
94
+ se_branch = layers.Conv2D(filters=8, kernel_size=(3, 3), padding='same', activation='relu')(se_quadrant)
95
+
96
+ # Apply padding to the side branches to match the dimensions of the main branch
97
+ # nw_branch = layers.UpSampling2D(size=(2, 2), interpolation='nearest')(nw_branch)
98
+ # ne_branch = layers.UpSampling2D(size=(2, 2), interpolation='nearest')(ne_branch)
99
+ # sw_branch = layers.UpSampling2D(size=(2, 2), interpolation='nearest')(sw_branch)
100
+ # se_branch = layers.UpSampling2D(size=(2, 2), interpolation='nearest')(se_branch)
101
+
102
+ # Fusion operations (concatenate the outputs from the main branch and side branches)
103
+ fusion = layers.concatenate([y, nw_branch, ne_branch, sw_branch, se_branch], axis=-1)
104
+
105
+ # Additional convolution layer to combine the fused features
106
+ x = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(fusion)
107
+ x=layers.MaxPool2D(pool_size=(2, 2))(x)
108
+ # Final dense layer for further processing
109
+ nw_branch = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(nw_branch)
110
+
111
+ ne_branch = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(ne_branch)
112
+ sw_branch = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(sw_branch)
113
+ se_branch = layers.Conv2D(filters=16, kernel_size=(3, 3), padding='same', activation='relu')(se_branch)
114
+ nw_branch = layers.MaxPool2D(pool_size=(2, 2))(nw_branch)
115
+ ne_branch = layers.MaxPool2D(pool_size=(2, 2))(ne_branch)
116
+ sw_branch = layers.MaxPool2D(pool_size=(2, 2))(sw_branch)
117
+ se_branch = layers.MaxPool2D(pool_size=(2, 2))(se_branch)
118
+
119
+ fusion = layers.concatenate([x, nw_branch, ne_branch, sw_branch, se_branch], axis=-1)
120
+ x = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(fusion)
121
+ x=layers.MaxPool2D(pool_size=(2, 2))(x)
122
+
123
+ nw_branch = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(nw_branch)
124
+
125
+ ne_branch = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(ne_branch)
126
+ sw_branch = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(sw_branch)
127
+ se_branch = layers.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(se_branch)
128
+ nw_branch = layers.MaxPool2D(pool_size=(2, 2))(nw_branch)
129
+ ne_branch = layers.MaxPool2D(pool_size=(2, 2))(ne_branch)
130
+ sw_branch = layers.MaxPool2D(pool_size=(2, 2))(sw_branch)
131
+ se_branch = layers.MaxPool2D(pool_size=(2, 2))(se_branch)
132
+
133
+ fusion = layers.concatenate([x, nw_branch, ne_branch, sw_branch, se_branch], axis=-1)
134
+ x = layers.Conv2D(filters=32, kernel_size=(3, 3), activation='relu')(fusion)
135
+ x=layers.Conv2D(filters=32, kernel_size=(3, 3), activation=None)(x)
136
+ # Create and return the model
137
+ x=layers.Flatten()(x)
138
+ model = models.Model(inputs=input_tensor, outputs=x)
139
+ return model
140
+
141
+ # Define input shape (batch_size, height, width, channels)
142
+ # input_shape = (95, 95, 8) # Example input shape (95x95 spatial resolution, 3 channels)
143
+
144
+ # # Build the model
145
+ # model = radial_structure_subnet(input_shape)
146
+
147
+ # # Model summary
148
+ # model.summary()
149
+
150
+ def build_cnn_model(input_shape=(8, 8, 1)):
151
+ # Define the input layer
152
+ input_tensor = layers.Input(shape=input_shape)
153
+
154
+ # Convolutional layer
155
+ x = layers.Conv2D(64, (3, 3), padding='same')(input_tensor)
156
+ x = layers.BatchNormalization()(x)
157
+ x = layers.ReLU()(x)
158
+
159
+ # Flatten layer
160
+ x = layers.Flatten()(x)
161
+
162
+ # Create the model
163
+ model = models.Model(inputs=input_tensor, outputs=x)
164
+
165
+ return model
166
+
167
+ from tensorflow.keras import layers, models, Input # type: ignore
168
+
169
+ def build_combined_model():
170
+ # Define input shapes
171
+ input_shape_3d = (8, 95, 95, 2)
172
+ input_shape_radial = (95, 95, 8)
173
+ input_shape_cnn = (8, 8, 1)
174
+
175
+ input_shape_latitude = (8,)
176
+ input_shape_longitude = (8,)
177
+ input_shape_other = (9,)
178
+
179
+ # Build individual models
180
+ model_3d = build_3d_conv_lstm_model(input_shape=input_shape_3d)
181
+ model_radial = radial_structure_subnet(input_shape=input_shape_radial)
182
+ model_cnn = build_cnn_model(input_shape=input_shape_cnn)
183
+
184
+ # Define new inputs
185
+ input_latitude = Input(shape=input_shape_latitude ,name="latitude_input")
186
+ input_longitude = Input(shape=input_shape_longitude, name="longitude_input")
187
+ input_other = Input(shape=input_shape_other, name="other_input")
188
+
189
+ # Flatten the additional inputs
190
+ flat_latitude = layers.Dense(32,activation='relu')(input_latitude)
191
+ flat_longitude = layers.Dense(32,activation='relu')(input_longitude)
192
+ flat_other = layers.Dense(64,activation='relu')(input_other)
193
+
194
+ # Combine all outputs
195
+ combined = layers.concatenate([
196
+ model_3d.output,
197
+ model_radial.output,
198
+ model_cnn.output,
199
+ flat_latitude,
200
+ flat_longitude,
201
+ flat_other
202
+ ])
203
+
204
+ # Add dense layers for final processing
205
+ x = layers.Dense(128, activation='relu')(combined)
206
+ x = layers.Dense(1, activation=None)(x)
207
+
208
+ # Create the final model
209
+ final_model = models.Model(
210
+ inputs=[model_3d.input, model_radial.input, model_cnn.input,
211
+ input_latitude, input_longitude, input_other ],
212
+ outputs=x
213
+ )
214
+
215
+ return final_model
216
+
217
+ import h5py
218
+ with h5py.File(r"lstm3dcnn-model.h5", 'r') as f:
219
+ print(f.attrs.get('keras_version'))
220
+ print(f.attrs.get('backend'))
221
+ print("Model layers:", list(f['model_weights'].keys()))
222
+
223
+ model = build_combined_model() # Your original model building function
224
+ model.load_weights(r"lstm3dcnn-model.h5")
225
+
226
+
227
+ def predict_lstm(reduced_images_test,hov_m_test,test_vmax_3d,lat_test,lon_test,int_diff_test):
228
+ y=model.predict([reduced_images_test,hov_m_test,test_vmax_3d,lat_test,lon_test,int_diff_test ])
229
  return y