美文网首页
tensorflow给训练图像添加噪声

tensorflow给训练图像添加噪声

作者: 求索_700e | 来源:发表于2019-04-17 09:23 被阅读0次

    import tensorflow as tf

    import cv2

    import os

    import numpy as np

    os.environ["CUDA_VISIBLE_DEVICES"] = "3"

    path="/home/ta/Desktop/gs_for_test/1.bmp"

    ori=cv2.imread(path, cv2.IMREAD_GRAYSCALE)

    img=tf.convert_to_tensor(ori)

    noise=tf.random_normal(shape=img.shape, mean=0, stddev=50)

    drop_noise=tf.nn.dropout(noise, 0.01)

    final=tf.add(img, tf.cast(drop_noise, dtype=tf.uint8))

    cv2.namedWindow('img',cv2.WINDOW_KEEPRATIO)

    cv2.namedWindow('final',cv2.WINDOW_KEEPRATIO)

    with tf.Session() as sess:

          fimg=sess.run(final)

          img__=sess.run(img)

          cv2.imshow("final", fimg)

          cv2.imshow("img", img__)

           cv2.waitKey()

    相关文章

      网友评论

          本文标题:tensorflow给训练图像添加噪声

          本文链接:https://www.haomeiwen.com/subject/goqgwqtx.html