Skip to content

Commit

Permalink
Summary
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryRyumin committed Dec 7, 2023
1 parent bdf5be5 commit 5b1437a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
20 changes: 13 additions & 7 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, name='lstm_128_a_hc')(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", name='dense_256')(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,7 +1843,10 @@ 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])
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 @@ -1976,7 +1979,10 @@ 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])
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 @@ -2547,7 +2553,7 @@ 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))
except TypeError:
code_error_pred_hc = 1
except Exception:
Expand All @@ -2557,7 +2563,7 @@ def get_audio_union_predictions(
# Отправка нейросетевых признаков в нейросетевую модель
pred_melspectrogram, _ = self.audio_model_nn_(
np.array(melspectrogram_features, dtype=np.float16)
).numpy()
)
except TypeError:
code_error_pred_melspectrogram = 1
except Exception:
Expand All @@ -2576,7 +2582,7 @@ def get_audio_union_predictions(
return False

# Конкатенация оценок по экспертным и нейросетевым признакам
union_pred = self.__concat_pred(pred_hc, pred_melspectrogram, out=out)
union_pred = self.__concat_pred(pred_hc.numpy(), pred_melspectrogram.numpy(), out=out)

if len(union_pred) == 0:
return False
Expand Down
24 changes: 15 additions & 9 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, name='lstm_128_v_hc')(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,9 +2599,9 @@ 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), name='lstm_1024_v_nn')(
input_lstm
)
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)
x = tf.keras.layers.Dense(units=5)(x)
x = tf.keras.layers.Activation("linear")(x)
Expand Down Expand Up @@ -2855,7 +2855,10 @@ 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])
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 @@ -3123,7 +3126,10 @@ 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])
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 @@ -3700,15 +3706,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))
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))
except TypeError:
code_error_pred_nn = 1
except Exception:
Expand All @@ -3727,7 +3733,7 @@ def get_video_union_predictions(
return False

# Конкатенация оценок по экспертным и нейросетевым признакам
union_pred = self.__concat_pred(pred_hc, pred_nn, out=out)
union_pred = self.__concat_pred(pred_hc.numpy(), pred_nn.numpy(), out=out)

if len(union_pred) == 0:
return False
Expand Down

0 comments on commit 5b1437a

Please sign in to comment.