예제 #1
0
def forward_fn(inputs, is_train, data_format):
  """Forward pass function.

  Args:
  * inputs: inputs to the network's forward pass
  * is_train: whether to use the forward pass with training operations inserted
  * data_format: data format ('channels_last' OR 'channels_first')

  Returns:
  * inputs: outputs from the network's forward pass
  """

  # setup hyper-parameters
  nb_blocks = (FLAGS.resnet_size - 2) // 6
  bottleneck = False
  nb_classes = FLAGS.nb_classes
  nb_filters = 16
  kernel_size = 3
  conv_stride = 1
  first_pool_size = None
  first_pool_stride = None
  block_sizes = [nb_blocks] * 3
  block_strides = [1, 2, 2]

  # model definition
  model = ResNet.Model(
    FLAGS.resnet_size, bottleneck, nb_classes, nb_filters, kernel_size, conv_stride,
    first_pool_size, first_pool_stride, block_sizes, block_strides, data_format=data_format)
  inputs = model(inputs, is_train)

  return inputs
예제 #2
0
def forward_fn(inputs, is_train, data_format):
  """Forward pass function.

  Args:
  * inputs: inputs to the network's forward pass
  * is_train: whether to use the forward pass with training operations inserted
  * data_format: data format ('channels_last' OR 'channels_first')

  Returns:
  * inputs: outputs from the network's forward pass
  """

  # for deeper networks, use bottleneck layers for speed-up
  if FLAGS.resnet_size < 50:
    bottleneck = False
  else:
    bottleneck = True

  # setup hyper-parameters
  nb_classes = FLAGS.nb_classes
  nb_filters = 64
  kernel_size = 7
  conv_stride = 2
  first_pool_size = 3
  first_pool_stride = 2
  block_sizes = get_block_sizes(FLAGS.resnet_size)
  block_strides = [1, 2, 2, 2]

  # model definition
  model = ResNet.Model(
    FLAGS.resnet_size, bottleneck, nb_classes, nb_filters, kernel_size, conv_stride,
    first_pool_size, first_pool_stride, block_sizes, block_strides, data_format=data_format)
  inputs = model(inputs, is_train)

  return inputs