zoukankan      html  css  js  c++  java
  • tensorflow2.0——图像增强的训练相关代码

    (x,y),(x_test,y_test) = tf.keras.datasets.cifar10.load_data()
    x = x/255.
    x = tf.cast(x,tf.float32)
    x_test = x_test/255.
    x_test = tf.cast(x_test,tf.float32)
    
    y = tf.one_hot(y,depth=10)
    y=tf.squeeze(y)
    y_test = tf.one_hot(y_test,depth=10)
    y_test=tf.squeeze(y_test)
    
    
    datagen = tf.keras.preprocessing.image.ImageDataGenerator(
    # 在数据集上将“输入平均值”设置为0
    featurewise_center=False,
    # 将每个样本的平均值设置为0
    samplewise_center=False,
    # 将输入除以数据集的标准
    featurewise_std_normalization=False,
    # 将每个输入除以其标准
    samplewise_std_normalization=False,
    # apply ZCA whitening
    zca_whitening=False,
    # epsilon for ZCA whitening
    zca_epsilon=1e-06,
    # 在范围内(0度到180度)随机旋转图像
    rotation_range=0,
    # 随机水平移动图像
    width_shift_range=0.1,
    # 随机垂直移动图像
    height_shift_range=0.1,
    # 随机剪切设定范围
    shear_range=0.,
    # 设置随机缩放范围
    zoom_range=0.,
    # 设置随机信道移位的范围
    channel_shift_range=0.,
    # 设置输入边界外填充点的模式
    fill_mode='nearest',
    # 用于填充模式的值=“常量”
    cval=0.,
    # 随机翻转图像
    horizontal_flip=True,
    # 随机翻转图像
    vertical_flip=False,
    # 设置重缩放因子(在任何其他变换之前应用)
    rescale=None,
    # 设置将应用于每个输入的函数
    preprocessing_function=None,
    # 图像数据格式,可以是“频道优先”或“频道最后”
    data_format=None,
    # 保留用于验证的图像的分数(严格介于0和1之间)
    validation_split=0.0)
    datagen.fit(x) res_model = resnet18() res_model.compile(optimizer=opt,loss=tf.keras.losses.CategoricalCrossentropy(from_logits=True),metrics=['accuracy']) # res_model.fit(x,y,validation_data=(x_test,y_test),epochs=epochs,batch_size=bat, validation_freq=1) res_model.fit_generator(datagen.flow(x,y,batch_size=bat),validation_data=(x_test,y_test),epochs=epochs, validation_freq=1)
  • 相关阅读:
    Android 剪贴板操作方法在不同版本API下的使用
    Android android:persistentDrawingCache的几个默认属性值介绍
    android 4.0 external下功能库说明
    Android gc overhead limit exceeded
    android onTerminate()方法调用需要注意的点
    android onTrimMemory()和onLowMemory()
    思维游戏(3)之时间问题
    思维游戏(2)之几根蜡烛
    思维游戏之分辨姐妹(1)
    如何根据用例图写出用例描述
  • 原文地址:https://www.cnblogs.com/cxhzy/p/14151160.html
Copyright © 2011-2022 走看看