예제 #1
0
def _construct_model(model_type='resnet_v1_50'):
  """Constructs model for the desired type of CNN.

  Args:
    model_type: Type of model to be used.

  Returns:
    end_points: A dictionary from components of the network to the corresponding
      activations.

  Raises:
    ValueError: If the model_type is not supported.
  """
  # Placeholder input.
  images = array_ops.placeholder(
      dtypes.float32, shape=(1, None, None, 3), name=_INPUT_NODE)

  # Construct model.
  if model_type == 'inception_resnet_v2':
    _, end_points = inception.inception_resnet_v2_base(images)
  elif model_type == 'inception_resnet_v2-same':
    _, end_points = inception.inception_resnet_v2_base(
        images, align_feature_maps=True)
  elif model_type == 'inception_v2':
    _, end_points = inception.inception_v2_base(images)
  elif model_type == 'inception_v2-no-separable-conv':
    _, end_points = inception.inception_v2_base(
        images, use_separable_conv=False)
  elif model_type == 'inception_v3':
    _, end_points = inception.inception_v3_base(images)
  elif model_type == 'inception_v4':
    _, end_points = inception.inception_v4_base(images)
  elif model_type == 'alexnet_v2':
    _, end_points = alexnet.alexnet_v2(images)
  elif model_type == 'vgg_a':
    _, end_points = vgg.vgg_a(images)
  elif model_type == 'vgg_16':
    _, end_points = vgg.vgg_16(images)
  elif model_type == 'mobilenet_v1':
    _, end_points = mobilenet_v1.mobilenet_v1_base(images)
  elif model_type == 'mobilenet_v1_075':
    _, end_points = mobilenet_v1.mobilenet_v1_base(
        images, depth_multiplier=0.75)
  elif model_type == 'resnet_v1_50':
    _, end_points = resnet_v1.resnet_v1_50(
        images, num_classes=None, is_training=False, global_pool=False)
  elif model_type == 'resnet_v1_101':
    _, end_points = resnet_v1.resnet_v1_101(
        images, num_classes=None, is_training=False, global_pool=False)
  elif model_type == 'resnet_v1_152':
    _, end_points = resnet_v1.resnet_v1_152(
        images, num_classes=None, is_training=False, global_pool=False)
  elif model_type == 'resnet_v1_200':
    _, end_points = resnet_v1.resnet_v1_200(
        images, num_classes=None, is_training=False, global_pool=False)
  elif model_type == 'resnet_v2_50':
    _, end_points = resnet_v2.resnet_v2_50(
        images, num_classes=None, is_training=False, global_pool=False)
  elif model_type == 'resnet_v2_101':
    _, end_points = resnet_v2.resnet_v2_101(
        images, num_classes=None, is_training=False, global_pool=False)
  elif model_type == 'resnet_v2_152':
    _, end_points = resnet_v2.resnet_v2_152(
        images, num_classes=None, is_training=False, global_pool=False)
  elif model_type == 'resnet_v2_200':
    _, end_points = resnet_v2.resnet_v2_200(
        images, num_classes=None, is_training=False, global_pool=False)
  else:
    raise ValueError('Unsupported model_type %s.' % model_type)

  return end_points
예제 #2
0
def _construct_model(model_type='resnet_v1_50'):
    """Constructs model for the desired type of CNN.

  Args:
    model_type: Type of model to be used.

  Returns:
    end_points: A dictionary from components of the network to the corresponding
      activations.

  Raises:
    ValueError: If the model_type is not supported.
  """
    # Placeholder input.
    images = array_ops.placeholder(dtypes.float32,
                                   shape=(1, None, None, 3),
                                   name=_INPUT_NODE)

    # Construct model.
    if model_type == 'inception_resnet_v2':
        _, end_points = inception.inception_resnet_v2_base(images)
    elif model_type == 'inception_resnet_v2-same':
        _, end_points = inception.inception_resnet_v2_base(
            images, align_feature_maps=True)
    elif model_type == 'inception_v2':
        _, end_points = inception.inception_v2_base(images)
    elif model_type == 'inception_v2-no-separable-conv':
        _, end_points = inception.inception_v2_base(images,
                                                    use_separable_conv=False)
    elif model_type == 'inception_v3':
        _, end_points = inception.inception_v3_base(images)
    elif model_type == 'inception_v4':
        _, end_points = inception.inception_v4_base(images)
    elif model_type == 'alexnet_v2':
        _, end_points = alexnet.alexnet_v2(images)
    elif model_type == 'vgg_a':
        _, end_points = vgg.vgg_a(images)
    elif model_type == 'vgg_16':
        _, end_points = vgg.vgg_16(images)
    elif model_type == 'mobilenet_v1':
        _, end_points = mobilenet_v1.mobilenet_v1_base(images)
    elif model_type == 'mobilenet_v1_075':
        _, end_points = mobilenet_v1.mobilenet_v1_base(images,
                                                       depth_multiplier=0.75)
    elif model_type == 'resnet_v1_50':
        _, end_points = resnet_v1.resnet_v1_50(images,
                                               num_classes=None,
                                               is_training=False,
                                               global_pool=False)
    elif model_type == 'resnet_v1_101':
        _, end_points = resnet_v1.resnet_v1_101(images,
                                                num_classes=None,
                                                is_training=False,
                                                global_pool=False)
    elif model_type == 'resnet_v1_152':
        _, end_points = resnet_v1.resnet_v1_152(images,
                                                num_classes=None,
                                                is_training=False,
                                                global_pool=False)
    elif model_type == 'resnet_v1_200':
        _, end_points = resnet_v1.resnet_v1_200(images,
                                                num_classes=None,
                                                is_training=False,
                                                global_pool=False)
    elif model_type == 'resnet_v2_50':
        _, end_points = resnet_v2.resnet_v2_50(images,
                                               num_classes=None,
                                               is_training=False,
                                               global_pool=False)
    elif model_type == 'resnet_v2_101':
        _, end_points = resnet_v2.resnet_v2_101(images,
                                                num_classes=None,
                                                is_training=False,
                                                global_pool=False)
    elif model_type == 'resnet_v2_152':
        _, end_points = resnet_v2.resnet_v2_152(images,
                                                num_classes=None,
                                                is_training=False,
                                                global_pool=False)
    elif model_type == 'resnet_v2_200':
        _, end_points = resnet_v2.resnet_v2_200(images,
                                                num_classes=None,
                                                is_training=False,
                                                global_pool=False)
    else:
        raise ValueError('Unsupported model_type %s.' % model_type)

    return end_points