您当前的位置:首页 > IT编程 > Keras
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch |

自学教程:Python layers.DepthwiseConv2D方法代码示例

51自学网 2020-12-01 11:09:06
  Keras
这篇教程Python layers.DepthwiseConv2D方法代码示例写得很实用,希望能帮到您。

本文整理汇总了Python中keras.layers.DepthwiseConv2D方法的典型用法代码示例。如果您正苦于以下问题:Python layers.DepthwiseConv2D方法的具体用法?Python layers.DepthwiseConv2D怎么用?Python layers.DepthwiseConv2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块keras.layers的用法示例。

在下文中一共展示了layers.DepthwiseConv2D方法的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_tiny_depthwise_conv_same_pad

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def test_tiny_depthwise_conv_same_pad(self):        np.random.seed(1988)        input_dim = 16        input_shape = (input_dim, input_dim, 3)        depth_multiplier = 1        kernel_height = 3        kernel_width = 3        # Define a model        model = Sequential()        model.add(            DepthwiseConv2D(                depth_multiplier=depth_multiplier,                kernel_size=(kernel_height, kernel_width),                input_shape=input_shape,                padding="same",                strides=(1, 1),            )        )        # Set some random weights        model.set_weights([np.random.rand(*w.shape) for w in model.get_weights()])        # Test the keras model        self._test_model(model) 
开发者ID:apple,项目名称:coremltools,代码行数:27,代码来源:test_keras2_numeric.py


示例2: test_tiny_depthwise_conv_valid_pad

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def test_tiny_depthwise_conv_valid_pad(self):        np.random.seed(1988)        input_dim = 16        input_shape = (input_dim, input_dim, 3)        depth_multiplier = 1        kernel_height = 3        kernel_width = 3        # Define a model        model = Sequential()        model.add(            DepthwiseConv2D(                depth_multiplier=depth_multiplier,                kernel_size=(kernel_height, kernel_width),                input_shape=input_shape,                padding="valid",                strides=(1, 1),            )        )        # Set some random weights        model.set_weights([np.random.rand(*w.shape) for w in model.get_weights()])        # Test the keras model        self._test_model(model) 
开发者ID:apple,项目名称:coremltools,代码行数:27,代码来源:test_keras2_numeric.py


示例3: test_tiny_depthwise_conv_same_pad_depth_multiplier

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def test_tiny_depthwise_conv_same_pad_depth_multiplier(self):        np.random.seed(1988)        input_dim = 16        input_shape = (input_dim, input_dim, 3)        depth_multiplier = 4        kernel_height = 3        kernel_width = 3        # Define a model        model = Sequential()        model.add(            DepthwiseConv2D(                depth_multiplier=depth_multiplier,                kernel_size=(kernel_height, kernel_width),                input_shape=input_shape,                padding="same",                strides=(1, 1),            )        )        # Set some random weights        model.set_weights([np.random.rand(*w.shape) for w in model.get_weights()])        # Test the keras model        self._test_model(model) 
开发者ID:apple,项目名称:coremltools,代码行数:27,代码来源:test_keras2_numeric.py


示例4: test_tiny_depthwise_conv_valid_pad_depth_multiplier

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def test_tiny_depthwise_conv_valid_pad_depth_multiplier(self):        np.random.seed(1988)        input_dim = 16        input_shape = (input_dim, input_dim, 3)        depth_multiplier = 2        kernel_height = 3        kernel_width = 3        # Define a model        model = Sequential()        model.add(            DepthwiseConv2D(                depth_multiplier=depth_multiplier,                kernel_size=(kernel_height, kernel_width),                input_shape=input_shape,                padding="valid",                strides=(1, 1),            )        )        # Set some random weights        model.set_weights([np.random.rand(*w.shape) for w in model.get_weights()])        # Test the keras model        self._test_model(model) 
开发者ID:apple,项目名称:coremltools,代码行数:27,代码来源:test_keras2_numeric.py


示例5: _inverted_res_block

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id, skip_connection, rate=1):    in_channels = inputs.shape[-1].value  # inputs._keras_shape[-1]    pointwise_conv_filters = int(filters * alpha)    pointwise_filters = _make_divisible(pointwise_conv_filters, 8)    x = inputs    prefix = 'expanded_conv_{}_'.format(block_id)    if block_id:        # Expand        x = Conv2D(expansion * in_channels, kernel_size=1, padding='same',                   use_bias=False, activation=None,                   name=prefix + 'expand')(x)        x = BatchNormalization(epsilon=1e-3, momentum=0.999,                               name=prefix + 'expand_BN')(x)        x = Activation(relu6, name=prefix + 'expand_relu')(x)    else:        prefix = 'expanded_conv_'    # Depthwise    x = DepthwiseConv2D(kernel_size=3, strides=stride, activation=None,                        use_bias=False, padding='same', dilation_rate=(rate, rate),                        name=prefix + 'depthwise')(x)    x = BatchNormalization(epsilon=1e-3, momentum=0.999,                           name=prefix + 'depthwise_BN')(x)    x = Activation(relu6, name=prefix + 'depthwise_relu')(x)    # Project    x = Conv2D(pointwise_filters,               kernel_size=1, padding='same', use_bias=False, activation=None,               name=prefix + 'project')(x)    x = BatchNormalization(epsilon=1e-3, momentum=0.999,                           name=prefix + 'project_BN')(x)    if skip_connection:        return Add(name=prefix + 'add')([inputs, x])    # if in_channels == pointwise_filters and stride == 1:    #    return Add(name='res_connect_' + str(block_id))([inputs, x])    return x 
开发者ID:bubbliiiing,项目名称:Semantic-Segmentation,代码行数:42,代码来源:mobilenetV2.py


示例6: SepConv_BN

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def SepConv_BN(x, filters, prefix, stride=1, kernel_size=3, rate=1, depth_activation=False, epsilon=1e-3):    # 计算padding的数量,hw是否需要收缩    if stride == 1:        depth_padding = 'same'    else:        kernel_size_effective = kernel_size + (kernel_size - 1) * (rate - 1)        pad_total = kernel_size_effective - 1        pad_beg = pad_total // 2        pad_end = pad_total - pad_beg        x = ZeroPadding2D((pad_beg, pad_end))(x)        depth_padding = 'valid'        # 如果需要激活函数    if not depth_activation:        x = Activation('relu')(x)    # 分离卷积,首先3x3分离卷积,再1x1卷积    # 3x3采用膨胀卷积    x = DepthwiseConv2D((kernel_size, kernel_size), strides=(stride, stride), dilation_rate=(rate, rate),                        padding=depth_padding, use_bias=False, name=prefix + '_depthwise')(x)    x = BatchNormalization(name=prefix + '_depthwise_BN', epsilon=epsilon)(x)    if depth_activation:        x = Activation('relu')(x)    # 1x1卷积,进行压缩    x = Conv2D(filters, (1, 1), padding='same',               use_bias=False, name=prefix + '_pointwise')(x)    x = BatchNormalization(name=prefix + '_pointwise_BN', epsilon=epsilon)(x)    if depth_activation:        x = Activation('relu')(x)    return x 
开发者ID:bubbliiiing,项目名称:Semantic-Segmentation,代码行数:34,代码来源:deeplab.py


示例7: SepConv_BN

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def SepConv_BN(x, filters, prefix, stride=1, kernel_size=3, rate=1, depth_activation=False, epsilon=1e-3):    """ SepConv with BN between depthwise & pointwise. Optionally add activation after BN        Implements right "same" padding for even kernel sizes        Args:            x: input tensor            filters: num of filters in pointwise convolution            prefix: prefix before name            stride: stride at depthwise conv            kernel_size: kernel size for depthwise convolution            rate: atrous rate for depthwise convolution            depth_activation: flag to use activation between depthwise & poinwise convs            epsilon: epsilon to use in BN layer    """    if stride == 1:        depth_padding = 'same'    else:        kernel_size_effective = kernel_size + (kernel_size - 1) * (rate - 1)        pad_total = kernel_size_effective - 1        pad_beg = pad_total // 2        pad_end = pad_total - pad_beg        x = ZeroPadding2D((pad_beg, pad_end))(x)        depth_padding = 'valid'    if not depth_activation:        x = Activation('relu')(x)    x = DepthwiseConv2D((kernel_size, kernel_size), strides=(stride, stride), dilation_rate=(rate, rate),                        padding=depth_padding, use_bias=False, name=prefix + '_depthwise')(x)    x = BatchNormalization(name=prefix + '_depthwise_BN', epsilon=epsilon)(x)    if depth_activation:        x = Activation('relu')(x)    x = Conv2D(filters, (1, 1), padding='same',               use_bias=False, name=prefix + '_pointwise')(x)    x = BatchNormalization(name=prefix + '_pointwise_BN', epsilon=epsilon)(x)    if depth_activation:        x = Activation('relu')(x)    return x 
开发者ID:andrewekhalel,项目名称:edafa,代码行数:40,代码来源:model.py


示例8: _inverted_res_block

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id, skip_connection, rate=1):    in_channels = inputs._keras_shape[-1]    pointwise_conv_filters = int(filters * alpha)    pointwise_filters = _make_divisible(pointwise_conv_filters, 8)    x = inputs    prefix = 'expanded_conv_{}_'.format(block_id)    if block_id:        # Expand        x = Conv2D(expansion * in_channels, kernel_size=1, padding='same',                   use_bias=False, activation=None,                   name=prefix + 'expand')(x)        x = BatchNormalization(epsilon=1e-3, momentum=0.999,                               name=prefix + 'expand_BN')(x)        x = Activation(relu6, name=prefix + 'expand_relu')(x)    else:        prefix = 'expanded_conv_'    # Depthwise    x = DepthwiseConv2D(kernel_size=3, strides=stride, activation=None,                        use_bias=False, padding='same', dilation_rate=(rate, rate),                        name=prefix + 'depthwise')(x)    x = BatchNormalization(epsilon=1e-3, momentum=0.999,                           name=prefix + 'depthwise_BN')(x)    x = Activation(relu6, name=prefix + 'depthwise_relu')(x)    # Project    x = Conv2D(pointwise_filters,               kernel_size=1, padding='same', use_bias=False, activation=None,               name=prefix + 'project')(x)    x = BatchNormalization(epsilon=1e-3, momentum=0.999,                           name=prefix + 'project_BN')(x)    if skip_connection:        return Add(name=prefix + 'add')([inputs, x])    # if in_channels == pointwise_filters and stride == 1:    #    return Add(name='res_connect_' + str(block_id))([inputs, x])    return x 
开发者ID:andrewekhalel,项目名称:edafa,代码行数:42,代码来源:model.py


示例9: __init__

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def __init__(self, model):        super(Keras2Parser, self).__init__()        # load model files into Keras graph        if isinstance(model, _string_types):            try:                # Keras 2.1.6                from keras.applications.mobilenet import relu6                from keras.applications.mobilenet import DepthwiseConv2D                model = _keras.models.load_model(                    model,                    custom_objects={                        'relu6': _keras.applications.mobilenet.relu6,                        'DepthwiseConv2D': _keras.applications.mobilenet.DepthwiseConv2D                    }                )            except:                # Keras. 2.2.2                import keras.layers as layers                model = _keras.models.load_model(                    model,                    custom_objects={                        'relu6': layers.ReLU(6, name='relu6'),                        'DepthwiseConv2D': layers.DepthwiseConv2D                    }                )            self.weight_loaded = True        elif isinstance(model, tuple):            model = self._load_model(model[0], model[1])        else:            assert False        # _keras.utils.plot_model(model, "model.png", show_shapes = True)        # Build network graph        self.data_format = _keras.backend.image_data_format()        self.keras_graph = Keras2Graph(model)        self.keras_graph.build()        self.lambda_layer_count = 0 
开发者ID:microsoft,项目名称:MMdnn,代码行数:43,代码来源:keras2_parser.py


示例10: _emit_convolution

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def _emit_convolution(self, IR_node, conv_type):        self.used_layers.add('Conv')        # assert IR_node.get_attr('group', 1) == 1        group = IR_node.get_attr("group", 1)        if conv_type.endswith('Transpose'):            filters = IR_node.get_attr('kernel_shape')[-2]        else:            filters = IR_node.get_attr('kernel_shape')[-1]        filters_str = 'filters={}'.format(filters) if not conv_type.endswith('DepthwiseConv2D') else 'depth_multiplier={}'.format(filters)        # change dw from filters to 1        input_node, padding = self._defuse_padding(IR_node)        dilations = IR_node.get_attr('dilations')        if not dilations or len(dilations) == 2:            # reset the default dilation            dilations = [1] * len(IR_node.get_attr('kernel_shape'))        code = "{:<15} = convolution(weights_dict, name='{}', input={}, group={}, conv_type='{}', {}, kernel_size={}, strides={}, dilation_rate={}, padding='{}', use_bias={})".format(            IR_node.variable_name,            IR_node.name,            input_node,            group,            conv_type,            filters_str,            tuple(IR_node.get_attr('kernel_shape')[:-2]),            tuple(IR_node.get_attr('strides')[1:-1]),            tuple(dilations[1:-1]),            padding,            IR_node.get_attr('use_bias'))        return code 
开发者ID:microsoft,项目名称:MMdnn,代码行数:38,代码来源:keras2_emitter.py


示例11: emit_DepthwiseConv

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def emit_DepthwiseConv(self, IR_node, in_scope=False):        try:            from keras.applications.mobilenet import DepthwiseConv2D            return self._emit_convolution(IR_node, 'keras.applications.mobilenet.DepthwiseConv2D')        except:            return self._emit_convolution(IR_node, 'layers.DepthwiseConv2D') 
开发者ID:microsoft,项目名称:MMdnn,代码行数:8,代码来源:keras2_emitter.py


示例12: _layer_Conv

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def _layer_Conv(self):        self.add_body(0, """def convolution(weights_dict, name, input, group, conv_type, filters=None, **kwargs):    if not conv_type.startswith('layer'):        layer = keras.applications.mobilenet.DepthwiseConv2D(name=name, **kwargs)(input)        return layer    elif conv_type == 'layers.DepthwiseConv2D':        layer = layers.DepthwiseConv2D(name=name, **kwargs)(input)        return layer        inp_filters = K.int_shape(input)[-1]    inp_grouped_channels = int(inp_filters / group)    out_grouped_channels = int(filters / group)    group_list = []    if group == 1:        func = getattr(layers, conv_type.split('.')[-1])        layer = func(name = name, filters = filters, **kwargs)(input)        return layer    weight_groups = list()    if not weights_dict == None:        w = np.array(weights_dict[name]['weights'])        weight_groups = np.split(w, indices_or_sections=group, axis=-1)    for c in range(group):        x = layers.Lambda(lambda z: z[..., c * inp_grouped_channels:(c + 1) * inp_grouped_channels])(input)        x = layers.Conv2D(name=name + "_" + str(c), filters=out_grouped_channels, **kwargs)(x)        weights_dict[name + "_" + str(c)] = dict()        weights_dict[name + "_" + str(c)]['weights'] = weight_groups[c]        group_list.append(x)    layer = layers.concatenate(group_list, axis = -1)    if 'bias' in weights_dict[name]:        b = K.variable(weights_dict[name]['bias'], name = name + "_bias")        layer = layer + b    return layer""") 
开发者ID:microsoft,项目名称:MMdnn,代码行数:35,代码来源:keras2_emitter.py


示例13: load_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def load_model(self):        global Graph  # multiprocess-able        config = tf.ConfigProto()        config.gpu_options.allow_growth = True        config.gpu_options.per_process_gpu_memory_fraction = 0.3        set_session(tf.Session(config=config))        # model.99-0.98.h5        files = glob.glob('models/{}/model.*.h5'.format(self.model_name))        if len(files) == 0:            print('Trained model not found from "models/{}/model.*.h5"'.format(self.model_name))            print('Building new model because model file not found...')            return self.build_model(self.kernel, self.stride)        last_file = max(files, key=os.path.getctime)        file_name = last_file.replace('//', '/').split('/')[-1].replace('model.', '').replace('.h5', '')        self.epoch = int(file_name.split('-')[0])        acc = float(file_name.split('-')[1])        with CustomObjectScope({'relu6': tf.nn.relu6, 'DepthwiseConv2D': keras.layers.DepthwiseConv2D, 'tf': tf}):            model = load_model(last_file)        model.summary()        Graph = tf.get_default_graph()        print('Loaded last model - {}, epoch: {}, acc: {}'.format(last_file, self.epoch, acc))        return model 
开发者ID:YoongiKim,项目名称:Walk-Assistant,代码行数:35,代码来源:model.py


示例14: _bottleneck

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def _bottleneck(inputs, filters, kernel, t, s, r=False):    """Bottleneck    This function defines a basic bottleneck structure.    # Arguments        inputs: Tensor, input tensor of conv layer.        filters: Integer, the dimensionality of the output space.        kernel: An integer or tuple/list of 2 integers, specifying the            width and height of the 2D convolution window.        t: Integer, expansion factor.            t is always applied to the input size.        s: An integer or tuple/list of 2 integers,specifying the strides            of the convolution along the width and height.Can be a single            integer to specify the same value for all spatial dimensions.        r: Boolean, Whether to use the residuals.    # Returns        Output tensor.    """    channel_axis = 1 if K.image_data_format() == 'channels_first' else -1    tchannel = K.int_shape(inputs)[channel_axis] * t    x = _conv_block(inputs, tchannel, (1, 1), (1, 1))    x = Dist(DepthwiseConv2D(kernel, strides=(s, s), depth_multiplier=1, padding='same'))(x)    x = Dist(BatchNormalization(axis=channel_axis))(x)    x = Dist(Activation(relu6))(x)    x = Dist(Conv2D(filters, (1, 1), strides=(1, 1), padding='same'))(x)    x = Dist(BatchNormalization(axis=channel_axis))(x)    if r:        x = add([x, inputs])    return x 
开发者ID:YoongiKim,项目名称:Walk-Assistant,代码行数:35,代码来源:mobilenet_v2.py


示例15: test_tiny_depthwise_conv_same_pad_depth_multiplier

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def test_tiny_depthwise_conv_same_pad_depth_multiplier(self):      np.random.seed(1988)      input_dim = 16      input_shape = (input_dim, input_dim, 3)      depth_multiplier = 4      kernel_height = 3      kernel_width = 3      # Define a model      model = Sequential()      model.add(DepthwiseConv2D(depth_multiplier=depth_multiplier, kernel_size=(kernel_height, kernel_width),                                input_shape=input_shape, padding='same', strides=(1, 1)))      # Set some random weights      model.set_weights([np.random.rand(*w.shape) for w in model.get_weights()])      # Test the keras model      self._test_keras_model(model) 
开发者ID:tf-coreml,项目名称:tf-coreml,代码行数:17,代码来源:test_tf_keras_layers.py


示例16: test_tiny_depthwise_conv_valid_pad_depth_multiplier

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def test_tiny_depthwise_conv_valid_pad_depth_multiplier(self):      np.random.seed(1988)      input_dim = 16      input_shape = (input_dim, input_dim, 3)      depth_multiplier = 2      kernel_height = 3      kernel_width = 3      # Define a model      model = Sequential()      model.add(DepthwiseConv2D(depth_multiplier=depth_multiplier, kernel_size=(kernel_height, kernel_width),                                input_shape=input_shape, padding='valid', strides=(1, 1)))      # Set some random weights      model.set_weights([np.random.rand(*w.shape) for w in model.get_weights()])      # Test the keras model      self._test_keras_model(model) 
开发者ID:tf-coreml,项目名称:tf-coreml,代码行数:17,代码来源:test_tf_keras_layers.py


示例17: relu6

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def relu6(x):    return K.relu(x, max_value=6)# DepthwiseConv2D is included in case you have an older version of keras which does not contain DepthwiseConv2D 
开发者ID:JonathanCMitchell,项目名称:mobilenet_v2_keras,代码行数:6,代码来源:mobilenetv2.py


示例18: __init__

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def __init__(self,                 kernel_size,                 strides=(1, 1),                 padding='valid',                 depth_multiplier=1,                 data_format=None,                 activation=None,                 use_bias=True,                 depthwise_initializer='glorot_uniform',                 bias_initializer='zeros',                 depthwise_regularizer=None,                 bias_regularizer=None,                 activity_regularizer=None,                 depthwise_constraint=None,                 bias_constraint=None,                 **kwargs):        super(DepthwiseConv2D, self).__init__(            filters=None,            kernel_size=kernel_size,            strides=strides,            padding=padding,            data_format=data_format,            activation=activation,            use_bias=use_bias,            bias_regularizer=bias_regularizer,            activity_regularizer=activity_regularizer,            bias_constraint=bias_constraint,            **kwargs)        self.depth_multiplier = depth_multiplier        self.depthwise_initializer = initializers.get(depthwise_initializer)        self.depthwise_regularizer = regularizers.get(depthwise_regularizer)        self.depthwise_constraint = constraints.get(depthwise_constraint)        self.bias_initializer = initializers.get(bias_initializer) 
开发者ID:JonathanCMitchell,项目名称:mobilenet_v2_keras,代码行数:35,代码来源:mobilenetv2.py


示例19: build

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def build(self, input_shape):        if len(input_shape) < 4:            raise ValueError('Inputs to `DepthwiseConv2D` should have rank 4. '                             'Received input shape:', str(input_shape))        if self.data_format == 'channels_first':            channel_axis = 1        else:            channel_axis = 3        if input_shape[channel_axis] is None:            raise ValueError('The channel dimension of the inputs to '                             '`DepthwiseConv2D` '                             'should be defined. Found `None`.')        input_dim = int(input_shape[channel_axis])        depthwise_kernel_shape = (self.kernel_size[0],                                  self.kernel_size[1],                                  input_dim,                                  self.depth_multiplier)        self.depthwise_kernel = self.add_weight(            shape=depthwise_kernel_shape,            initializer=self.depthwise_initializer,            name='depthwise_kernel',            regularizer=self.depthwise_regularizer,            constraint=self.depthwise_constraint)        if self.use_bias:            self.bias = self.add_weight(shape=(input_dim * self.depth_multiplier,),                                        initializer=self.bias_initializer,                                        name='bias',                                        regularizer=self.bias_regularizer,                                        constraint=self.bias_constraint)        else:            self.bias = None        # Set input spec.        self.input_spec = InputSpec(ndim=4, axes={channel_axis: input_dim})        self.built = True 
开发者ID:JonathanCMitchell,项目名称:mobilenet_v2_keras,代码行数:38,代码来源:mobilenetv2.py


示例20: get_config

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def get_config(self):        config = super(DepthwiseConv2D, self).get_config()        config.pop('filters')        config.pop('kernel_initializer')        config.pop('kernel_regularizer')        config.pop('kernel_constraint')        config['depth_multiplier'] = self.depth_multiplier        config['depthwise_initializer'] = initializers.serialize(            self.depthwise_initializer)        config['depthwise_regularizer'] = regularizers.serialize(            self.depthwise_regularizer)        config['depthwise_constraint'] = constraints.serialize(            self.depthwise_constraint)        return config 
开发者ID:JonathanCMitchell,项目名称:mobilenet_v2_keras,代码行数:16,代码来源:mobilenetv2.py


示例21: _inverted_res_block

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id):    in_channels = inputs._keras_shape[-1]    prefix = 'features.' + str(block_id) + '.conv.'    pointwise_conv_filters = int(filters * alpha)    pointwise_filters = _make_divisible(pointwise_conv_filters, 8)    # Expand    x = Conv2D(expansion * in_channels, kernel_size=1, padding='same',               use_bias=False, activation=None,               name='mobl%d_conv_expand' % block_id)(inputs)    x = BatchNormalization(epsilon=1e-3, momentum=0.999,                           name='bn%d_conv_bn_expand' %                           block_id)(x)    x = Activation(relu6, name='conv_%d_relu' % block_id)(x)    # Depthwise    x = DepthwiseConv2D(kernel_size=3, strides=stride, activation=None,                        use_bias=False, padding='same',                        name='mobl%d_conv_depthwise' % block_id)(x)    x = BatchNormalization(epsilon=1e-3, momentum=0.999,                           name='bn%d_conv_depthwise' % block_id)(x)    x = Activation(relu6, name='conv_dw_%d_relu' % block_id)(x)    # Project    x = Conv2D(pointwise_filters,               kernel_size=1, padding='same', use_bias=False, activation=None,               name='mobl%d_conv_project' % block_id)(x)    x = BatchNormalization(epsilon=1e-3, momentum=0.999,                           name='bn%d_conv_bn_project' % block_id)(x)    if in_channels == pointwise_filters and stride == 1:        return Add(name='res_connect_' + str(block_id))([inputs, x])    return x 
开发者ID:JonathanCMitchell,项目名称:mobilenet_v2_keras,代码行数:37,代码来源:mobilenetv2.py


示例22: _bottleneck

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def _bottleneck(inputs, filters, kernel, t, alpha, s, r=False):    """Bottleneck    This function defines a basic bottleneck structure.    # Arguments        inputs: Tensor, input tensor of conv layer.        filters: Integer, the dimensionality of the output space.        kernel: An integer or tuple/list of 2 integers, specifying the            width and height of the 2D convolution window.        t: Integer, expansion factor.            t is always applied to the input size.        s: An integer or tuple/list of 2 integers,specifying the strides            of the convolution along the width and height.Can be a single            integer to specify the same value for all spatial dimensions.        alpha: Integer, width multiplier.        r: Boolean, Whether to use the residuals.    # Returns        Output tensor.    """    channel_axis = 1 if K.image_data_format() == 'channels_first' else -1    # Depth    tchannel = K.int_shape(inputs)[channel_axis] * t    # Width    cchannel = int(filters * alpha)    x = _conv_block(inputs, tchannel, (1, 1), (1, 1))    x = DepthwiseConv2D(kernel, strides=(s, s), depth_multiplier=1, padding='same')(x)    x = BatchNormalization(axis=channel_axis)(x)    x = Activation(relu6)(x)    x = Conv2D(cchannel, (1, 1), strides=(1, 1), padding='same')(x)    x = BatchNormalization(axis=channel_axis)(x)    if r:        x = Add()([x, inputs])    return x 
开发者ID:xiaochus,项目名称:MobileNetV2,代码行数:42,代码来源:mobilenet_v2.py


示例23: __init__

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def __init__(self, filters, kernels, groups,                 type='conv', conv_kwargs=None,                 **kwargs):        super(GroupConvolution, self).__init__(**kwargs)        if conv_kwargs is None:            conv_kwargs = {                'strides': (1, 1),                'padding': 'same',                'dilation_rate': (1, 1),                'use_bias': False,            }        self.filters = filters        self.kernels = kernels        self.groups = groups        self.type = type        self.strides = conv_kwargs.get('strides', (1, 1))        self.padding = conv_kwargs.get('padding', 'same')        self.dilation_rate = conv_kwargs.get('dilation_rate', (1, 1))        self.use_bias = conv_kwargs.get('use_bias', False)        self.conv_kwargs = conv_kwargs or {}        assert type in ['conv', 'depthwise_conv']        if type == 'conv':            splits = self._split_channels(filters, self.groups)            self._layers = [layers.Conv2D(splits[i], kernels[i],                                          strides=self.strides,                                          padding=self.padding,                                          dilation_rate=self.dilation_rate,                                          use_bias=self.use_bias,                                          kernel_initializer=MixNetConvInitializer())                            for i in range(groups)]        else:            self._layers = [layers.DepthwiseConv2D(kernels[i],                                                   strides=self.strides,                                                   padding=self.padding,                                                   dilation_rate=self.dilation_rate,                                                   use_bias=self.use_bias,                                                   kernel_initializer=MixNetConvInitializer())                            for i in range(groups)]        self.data_format = 'channels_last'        self._channel_axis = -1 
开发者ID:titu1994,项目名称:keras_mixnets,代码行数:47,代码来源:custom_objects.py


示例24: _load_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import DepthwiseConv2D [as 别名]def _load_model(self, model_network_path, model_weight_path):        """Load a keras model from disk        Parameters        ----------        model_network_path: str            Path where the model network path is (json file)        model_weight_path: str            Path where the model network weights are (hd5 file)        Returns        -------        model: A keras model        """        from keras.models import model_from_json        # Load the model network        json_file = open(model_network_path, 'r')        loaded_model_json = json_file.read()        json_file.close()        # Load the model weights        try:            from keras.applications.mobilenet import relu6            from keras.applications.mobilenet import DepthwiseConv2D            loaded_model = model_from_json(loaded_model_json, custom_objects={                'relu6': _keras.applications.mobilenet.relu6,                'DepthwiseConv2D': _keras.applications.mobilenet.DepthwiseConv2D})        except:            import keras.layers as layers            loaded_model = model_from_json(loaded_model_json, custom_objects={                'relu6': layers.ReLU(6, name='relu6'),                'DepthwiseConv2D': layers.DepthwiseConv2D})        if model_weight_path:            if os.path.isfile(model_weight_path):                loaded_model.load_weights(model_weight_path)                self.weight_loaded = True                print("Network file [{}] and [{}] is loaded successfully.".format(model_network_path, model_weight_path))            else:                print("Warning: Weights File [%s] is not found." % (model_weight_path))        return loaded_model 
开发者ID:microsoft,项目名称:MMdnn,代码行数:49,代码来源:keras2_parser.py


51自学网,即我要自学网,自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1