Skip to content

Commit

Permalink
Merge pull request #2 from ElenaRyumina/main
Browse files Browse the repository at this point in the history
Update Audio and Video modules
  • Loading branch information
DmitryRyumin authored Dec 7, 2023
2 parents e58c092 + 523b4b5 commit bdf5be5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions oceanai/modules/lab/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ def load_audio_model_hc(

x = tf.keras.layers.LSTM(64, return_sequences=True)(input_lstm)
x = tf.keras.layers.Dropout(rate=0.2)(x)
x = tf.keras.layers.LSTM(128, return_sequences=False)(x)
x = tf.keras.layers.LSTM(128, return_sequences=False, name='lstm_128_a_hc')(x)
x = tf.keras.layers.Dropout(rate=0.2)(x)
x = tf.keras.layers.Dense(5, activation="linear")(x)

Expand Down Expand Up @@ -1590,7 +1590,7 @@ def load_audio_model_nn(
x = tf.keras.layers.Flatten()(x)
x = tf.keras.layers.Dense(512, activation="relu")(x)
x = tf.keras.layers.Dropout(0.5)(x)
x = tf.keras.layers.Dense(256, activation="relu")(x)
x = tf.keras.layers.Dense(256, activation="relu", name='dense_256')(x)
x = tf.keras.layers.Dense(5, activation="linear")(x)

self._audio_model_nn = tf.keras.models.Model(inputs=vgg_model.input, outputs=x)
Expand Down Expand Up @@ -1843,6 +1843,7 @@ def load_audio_model_weights_hc(
if self.__load_model_weights(url, force_reload, self._load_audio_model_weights_hc, out, False, run) is True:
try:
self._audio_model_hc.load_weights(self._url_last_filename)
self._audio_model_hc = tf.keras.models.Model(inputs=self._audio_model_hc.input, outputs=[self._audio_model_hc.output, self._audio_model_hc.get_layer('lstm_128_a_hc').output])
except Exception:
self._error(self._model_audio_hc_not_formation, out=out)
return False
Expand Down Expand Up @@ -1975,6 +1976,7 @@ def load_audio_model_weights_nn(
if self.__load_model_weights(url, force_reload, self._load_audio_model_weights_nn, out, False, run) is True:
try:
self._audio_model_nn.load_weights(self._url_last_filename)
self._audio_model_nn = tf.keras.models.Model(inputs=self._audio_model_nn.input, outputs=[self._audio_model_nn.output, self._audio_model_nn.get_layer('dense_256').output])
except Exception:
self._error(self._model_audio_nn_not_formation, out=out)
return False
Expand Down Expand Up @@ -2545,15 +2547,15 @@ def get_audio_union_predictions(

try:
# Оправка экспертных признаков в нейросетевую модель
pred_hc = self.audio_model_hc_(np.array(hc_features, dtype=np.float16)).numpy()
pred_hc, _ = self.audio_model_hc_(np.array(hc_features, dtype=np.float16)).numpy()
except TypeError:
code_error_pred_hc = 1
except Exception:
code_error_pred_hc = 2

try:
# Отправка нейросетевых признаков в нейросетевую модель
pred_melspectrogram = self.audio_model_nn_(
pred_melspectrogram, _ = self.audio_model_nn_(
np.array(melspectrogram_features, dtype=np.float16)
).numpy()
except TypeError:
Expand Down
10 changes: 6 additions & 4 deletions oceanai/modules/lab/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ def load_video_model_hc(

x = tf.keras.layers.LSTM(64, return_sequences=True)(input_lstm)
x = tf.keras.layers.Dropout(rate=0.2)(x)
x = tf.keras.layers.LSTM(128, return_sequences=False)(x)
x = tf.keras.layers.LSTM(128, return_sequences=False, name='lstm_128_v_hc')(x)
x = tf.keras.layers.Dropout(rate=0.2)(x)
x = tf.keras.layers.Dense(5, activation="linear")(x)

Expand Down Expand Up @@ -2599,7 +2599,7 @@ def load_video_model_nn(

input_lstm = tf.keras.Input(shape=(10, 512))

x = tf.keras.layers.LSTM(1024, return_sequences=False, kernel_regularizer=tf.keras.regularizers.l2(1e-3))(
x = tf.keras.layers.LSTM(1024, return_sequences=False, kernel_regularizer=tf.keras.regularizers.l2(1e-3), name='lstm_1024_v_nn')(
input_lstm
)
x = tf.keras.layers.Dropout(rate=0.2)(x)
Expand Down Expand Up @@ -2855,6 +2855,7 @@ def load_video_model_weights_hc(
if self.__load_model_weights(url, force_reload, self._load_video_model_weights_hc, out, False, run) is True:
try:
self._video_model_hc.load_weights(self._url_last_filename)
self._video_model_hc = tf.keras.models.Model(inputs=self._video_model_hc.input, outputs=[self._video_model_hc.output, self._video_model_hc.get_layer('lstm_128_v_hc').output])
except Exception:
self._error(self._model_video_hc_not_formation, out=out)
return False
Expand Down Expand Up @@ -3122,6 +3123,7 @@ def load_video_model_weights_nn(
if self.__load_model_weights(url, force_reload, self._load_video_model_weights_nn, out, False, run) is True:
try:
self._video_model_nn.load_weights(self._url_last_filename)
self._video_model_nn = tf.keras.models.Model(inputs=self._video_model_nn.input, outputs=[self._video_model_nn.output, self._video_model_nn.get_layer('lstm_1024_v_nn').output])
except Exception:
self._error(self._model_video_nn_not_formation, out=out)
return False
Expand Down Expand Up @@ -3698,15 +3700,15 @@ def get_video_union_predictions(

try:
# Оправка экспертных признаков в нейросетевую модель
pred_hc = self.video_model_hc_(np.array(hc_features, dtype=np.float16)).numpy()
pred_hc, _ = self.video_model_hc_(np.array(hc_features, dtype=np.float16)).numpy()
except TypeError:
code_error_pred_hc = 1
except Exception:
code_error_pred_hc = 2

try:
# Отправка нейросетевых признаков в нейросетевую модель
pred_nn = self.video_model_nn_(np.array(nn_features, dtype=np.float16)).numpy()
pred_nn, _= self.video_model_nn_(np.array(nn_features, dtype=np.float16)).numpy()
except TypeError:
code_error_pred_nn = 1
except Exception:
Expand Down

0 comments on commit bdf5be5

Please sign in to comment.