zoukankan      html  css  js  c++  java
  • Tensorflow学习笔记(一)

     图片分类问题:

      模型搭建:一般是卷积层与池化层的循环叠加,最后再用Flatten平铺,连接。卷积核一般为3X3、5X5等奇数卷积核。步长默认为1,激活函数为relu。

    model = keras.Sequential(
                [
                    layers.Conv2D(64, (3, 3), activation='relu', input_shape=(300, 300, 3))
                    , layers.MaxPooling2D()
                    , layers.Conv2D(128, (3, 3), activation='relu')
                    , layers.MaxPooling2D()
                    , layers.Conv2D(256, (3, 3), activation='relu')
                    , layers.MaxPooling2D()
                    , layers.Conv2D(512, (3, 3), activation='relu')
                    , layers.MaxPooling2D()
                    , layers.Conv2D(1024, (3, 3), activation='relu')
                    , layers.MaxPooling2D()
                    , layers.Flatten()
                    , layers.Dense(512, activation='relu')
                    , layers.Dense(len(index_to_type), activation='softmax')
                ]
            )

      1、二分类与多分类激活函数选择:

        softmax与sigmod都是图片分类激活函数,softmax用于图片多分类(成百上千种),sigmod用于二分类(非我即它)。

      2、二分类与多分类优化函数选择:

        binary_categorical用于二分类;sparse_categorical_crossentropy与categorical_crossentropy均用于图像多分类的损失优化函数,categorical_crossentropy用于数据是独热编码,sparse_categorical_crossentropy用于数字编码。

    model.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
    model.fit(ds,epochs=5,steps_per_epoch=len(img_paths)//16)
  • 相关阅读:
    资源与锁
    资源与锁
    Leetcode-Rotate List
    Leetcode-Unique Paths II
    Leetcode-Unique Paths
    Leetcode-Minimum Path Sum
    Leetcode-Sqrt(x)
    Leetcode-Set Matrix Zeroes
    Leetcode-Search a 2D Matrix
    Leetcode-Combinations
  • 原文地址:https://www.cnblogs.com/haheihei/p/13509442.html
Copyright © 2011-2022 走看看