inception代码
时间: 2023-11-03 18:06:55 浏览: 158
tensorflow实现Inception v3代码
好的,以下是 Inception v3 模型的 TensorFlow 代码:
```python
import tensorflow as tf
from tensorflow.keras import layers
def conv2d_bn(x, filters, kernel_size, strides=1, padding='same', activation='relu', use_bias=False):
x = layers.Conv2D(filters, kernel_size, strides=strides, padding=padding, use_bias=use_bias)(x)
x = layers.BatchNormalization()(x)
if activation:
x = layers.Activation(activation)(x)
return x
def InceptionV3(input_shape=(299, 299, 3), classes=1000):
img_input = layers.Input(shape=input_shape)
# Stem
x = conv2d_bn(img_input, 32, 3, strides=2, padding='valid')
x = conv2d_bn(x, 32, 3, padding='valid')
x = conv2d_bn(x,64, 3)
x = layers.MaxPooling2D(3, strides=2)(x)
x = conv2d_bn(x, 80, 1, padding='valid')
x = conv2d_bn(x, 192, 3, padding='valid')
x = layers.MaxPooling2D(3, strides=2)(x)
# Mixed 5b (Inception-A block): 35 x 35 x 256
branch_0 = conv2d_bn(x, 64, 1)
branch_1 = conv2d_bn(x, 48, 1)
branch_1 = conv2d_bn(branch_1, 64, 5)
branch_2 = conv2d_bn(x, 64, 1)
branch_2 = conv2d_bn(branch_2, 96, 3)
branch_2 = conv2d_bn(branch_2, 96, 3)
branch_3 = layers.AveragePooling2D(3, strides=1, padding='same')(x)
branch_3 = conv2d_bn(branch_3, 32, 1)
x = layers.concatenate([branch_0, branch_1, branch_2, branch_3], axis=3, name='mixed5b')
# ... (省略了其它 Inception 模块)
# Classification block
x = layers.GlobalAveragePooling2D(name='avg_pool')(x)
x = layers.Dense(classes, activation='softmax', name='predictions')(x)
# Create model
model = tf.keras.Model(img_input, x, name='inception_v3')
return model
```
阅读全文