tensorflow给训练图像添加噪声

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给训练图像添加噪声)