當前位置: 首頁>>代碼示例>>Python>>正文


Python model_base.ResNet方法代碼示例

本文整理匯總了Python中model_base.ResNet方法的典型用法代碼示例。如果您正苦於以下問題:Python model_base.ResNet方法的具體用法?Python model_base.ResNet怎麽用?Python model_base.ResNet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在model_base的用法示例。


在下文中一共展示了model_base.ResNet方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: forward_pass

# 需要導入模塊: import model_base [as 別名]
# 或者: from model_base import ResNet [as 別名]
def forward_pass(self, x, input_data_format='channels_last'):
    """Build the core model within the graph."""
    if self._data_format != input_data_format:
      if input_data_format == 'channels_last':
        # Computation requires channels_first.
        x = tf.transpose(x, [0, 3, 1, 2])
      else:
        # Computation requires channels_last.
        x = tf.transpose(x, [0, 2, 3, 1])

    # Image standardization.
    x = x / 128 - 1

    x = self._conv(x, 3, 16, 1)
    x = self._batch_norm(x)
    x = self._relu(x)

    # Use basic (non-bottleneck) block and ResNet V1 (post-activation).
    res_func = self._residual_v1

    # 3 stages of block stacking.
    for i in range(3):
      with tf.name_scope('stage'):
        for j in range(self.n):
          if j == 0:
            # First block in a stage, filters and strides may change.
            x = res_func(x, 3, self.filters[i], self.filters[i + 1],
                         self.strides[i])
          else:
            # Following blocks in a stage, constant filters and unit stride.
            x = res_func(x, 3, self.filters[i + 1], self.filters[i + 1], 1)

    x = self._global_avg_pool(x)
    x = self._fully_connected(x, self.num_classes)

    return x 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:38,代碼來源:cifar10_model.py

示例2: forward_pass

# 需要導入模塊: import model_base [as 別名]
# 或者: from model_base import ResNet [as 別名]
def forward_pass(self, x, input_data_format='channels_last'):
    """Build the core model within the graph."""
    if self._data_format != input_data_format:
      if input_data_format == 'channels_last':
        # Computation requires channels_first.
        x = tf.transpose(x, [0, 3, 1, 2])
      else:
        # Computation requires channels_last.
        x = tf.transpose(x, [0, 2, 3, 1])

    # Image standardization.
    x = x / 128 - 1

    x = self._conv(x, 3, 16, 1)
    x = self._batch_norm(x)
    x = self._relu(x)

    if self.version == 'v1':
      # Use basic (non-bottleneck) block and ResNet V1 (post-activation).
      res_func = self._residual_v1
    elif self.version == 'v2':
      # Use basic (non-bottleneck) block and ResNet V2 (pre-activation).
      res_func = self._residual_v2
    else:  # 'bv2'
      # Use bottleneck block and ResNet V2 (pre-activation).
      res_func = self._bottleneck_residual_v2

    # 3 stages of block stacking.
    for i in range(3):
      with tf.name_scope('stage'):
        for j in range(self.n):
          if j == 0:
            # First block in a stage, filters and strides may change.
            x = res_func(x, self.filters[i], self.filters[i + 1],
                         self.strides[i])
          else:
            # Following blocks in a stage, constant filters and unit stride.
            x = res_func(x, self.filters[i + 1], self.filters[i + 1], 1)

    x = self._global_avg_pool(x)
    x = self._fully_connected(x, self.num_classes, self.loss_type)

    return x 
開發者ID:richardaecn,項目名稱:class-balanced-loss,代碼行數:45,代碼來源:cifar_model.py


注:本文中的model_base.ResNet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。