使用Tensorlow 2.0实现CNN模型

时间:2019-11-19 09:06:21

标签: python tensorflow keras neural-network

由于我是该领域的新手,所以我的项目面临很多错误。请帮助我解决这些问题。 预先感谢

请下载以下文件,然后在jupyter中运行   https://1drv.ms/u/s!AhSiPNeVlPcLhkXPp_9eMWc9b_mC?e=4foE3S

亲切的问候, 玛扎尔·布哈里()

1 个答案:

答案 0 :(得分:0)

您应将inception_module填充更改为padding="same"。这样可以确保输出张量的高度和宽度与输入张量(32x32)相同。

   def inception_module(x,chanDim):
    # x is the input  and chanDim is the dimension at which the convolution is applied
    # channel dimension
    conv_1x1_64 = conv_module(x, 64, 1, 1, (1, 1), chanDim,padding='same') # Convol x with 64 filters of 1X1
    conv_1x1_96 = conv_module(x, 96, 1, 1, (1, 1), chanDim,padding="same") # convol x with 96 filters of 1X1
    conv_1x1_16 = conv_module(x, 16, 1, 1, (1, 1), chanDim,padding="same") # convol x with 16 filters of 1X1 
    conv_3x3 = conv_module(conv_1x1_96, 128, 3, 3, (1, 1), chanDim,padding="same") # convol conv_1x1_96 with 128 3X3 filters
    conv_5x5 = conv_module(conv_1x1_16, 32, 5, 5, (1, 1), chanDim,padding="same") # Convol the conv_1x1_16 with 32 5X5 filters
    maxpool = MaxPooling2D((3, 3), strides=(1, 1), padding='same')(x) # Perform MaxPooling of 3X3, with strides=1
    # padding='same'. Hint:  use MaxPooling2D function 
    conv_1x1_32 = conv_module(maxpool, 32, 1, 1, (1, 1), chanDim,padding="same") # convol maxpool with 32 filters of 1X1
    x = concatenate([conv_1x1_64, conv_3x3, conv_5x5,conv_1x1_32], axis=chanDim)

    return x