回答編集履歴

1

fix answer

2023/02/16 19:00

投稿

ps_aux_grep
ps_aux_grep

スコア1579

test CHANGED
@@ -1,12 +1,9 @@
1
- `x_true`を使うにはSubclassing APIを利用して,`keras.Model`の`compute_loss`をカスタマイズしてください.質問にある`custom_loss`を12行目で記述しました.
1
+ `x_true`を使うにはSubclassing APIを利用して,`keras.Model`の`compute_loss`をカスタマイズしてください.質問にある`custom_loss`を9行目で記述しました.
2
2
 
3
3
  ```Python
4
4
  import tensorflow as tf
5
- from keras.layers import Input, Concatenate, Permute, Dense, Activation, Add
5
+ from keras.layers import Input, Activation, Add, BatchNormalization, Conv2D
6
- from keras.layers import Dropout, BatchNormalization
7
- from keras.layers import Conv2D, Conv2DTranspose, AveragePooling2D
8
6
  from keras.models import Model
9
- from keras.callbacks import EarlyStopping, ReduceLROnPlateau, ModelCheckpoint
10
7
 
11
8
  class OriginalModel(Model):
12
9
  def compute_loss(self, x, y, y_pred, sample_weight):
@@ -18,11 +15,9 @@
18
15
  def ResBlock(ch, k):
19
16
  def apply(inputs):
20
17
  x = Conv2D(ch, k, padding = "same", kernel_initializer = "he_uniform")(inputs)
18
+ x = BatchNormalization()(x)
21
19
  x = Activation("swish")(x)
22
- x = BatchNormalization()(x)
23
- x = Conv2D(ch, k, padding = "same", kernel_initializer = "he_uniform")(x)
24
- x = Activation("swish")(x)
20
+ x = Conv2D(ch, k, padding = "same")(x)
25
- x = BatchNormalization()(x)
26
21
  return Add()([x, inputs])
27
22
  return apply
28
23