Guest User

Untitled

a guest
Oct 23rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. if (depth - 2) % 6 != 0:
  2. raise ValueError('depth should be 6n+2 (eg: 20, 32, 44 in [a])')
  3. # Start model definition.
  4. num_filters = 16
  5. num_res_blocks = int((depth - 2) / 6)
  6.  
  7. inputs = Input(shape=input_shape)
  8. x = resnet_layer(inputs=inputs)
  9. # Instantiate the stack of residual units
  10. for stack in range(3):
  11. for res_block in range(num_res_blocks):
  12. strides = 1
  13. if stack > 0 and res_block == 0: # first layer but not first stack
  14. strides = 2 # downsample
  15. y = resnet_layer(inputs=x,
  16. num_filters=num_filters,
  17. strides=strides)
  18. y = resnet_layer(inputs=y,
  19. num_filters=num_filters,
  20. activation=None)
  21. if stack > 0 and res_block == 0: # first layer but not first stack
  22. # linear projection residual shortcut connection to match
  23. # changed dims
  24. x = resnet_layer(inputs=x,
  25. num_filters=num_filters,
  26. kernel_size=1,
  27. strides=strides,
  28. activation=None,
  29. batch_normalization=False)
  30. x = keras.layers.add([x, y])
  31. x = Activation('relu')(x)
  32. #x = LeakyReLU()(x) #改relu -> LeakyReLU
  33. num_filters *= 2
  34.  
  35. # Add classifier on top.
  36. # v1 does not use BN after last shortcut connection-ReLU
  37. x = AveragePooling2D(pool_size=8)(x)
  38. y = Flatten()(x)
  39. outputs = Dense(num_classes,
  40. activation='softmax',
  41. kernel_initializer='he_normal')(y)
  42.  
  43. # Instantiate model.
  44. model = Model(inputs=inputs, outputs=outputs)
  45. return model
Add Comment
Please, Sign In to add comment