国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - 使用TensorFlow對圖像進行隨機旋轉的實現示例

使用TensorFlow對圖像進行隨機旋轉的實現示例

2020-04-09 12:17LiangJun.py Python

這篇文章主要介紹了使用TensorFlow對圖像進行隨機旋轉的實現示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

在使用深度學習對圖像進行訓練時,對圖像進行隨機旋轉有助于提升模型泛化能力。然而之前在做旋轉等預處理工作時,都是先對圖像進行旋轉后保存到本地,然后再輸入模型進行訓練,這樣的過程會增加工作量,如果圖片數量較多,生成旋轉的圖像會占用更多的空間。直接在訓練過程中便對圖像進行隨機旋轉,可有效提升工作效率節省硬盤空間。

使用TensorFlow對圖像進行隨機旋轉如下:

TensorFlow版本為1.13.1

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#-*- coding:utf-8 -*-
'''
  使用TensorFlow進行圖像的隨機旋轉示例
'''
 
import tensorflow as tf
import numpy as np
import cv2
import matplotlib.pyplot as plt
 
 
img = cv2.imread('tf.jpg')
img = cv2.resize(img,(220,220))
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
 
def tf_rotate(input_image, min_angle = -np.pi/2, max_angle = np.pi/2):
  '''
  TensorFlow對圖像進行隨機旋轉
  :param input_image: 圖像輸入
  :param min_angle: 最小旋轉角度
  :param max_angle: 最大旋轉角度
  :return: 旋轉后的圖像
  '''
  distorted_image = tf.expand_dims(input_image, 0)
  random_angles = tf.random.uniform(shape=(tf.shape(distorted_image)[0],), minval = min_angle , maxval = max_angle)
  distorted_image = tf.contrib.image.transform(
    distorted_image,
    tf.contrib.image.angles_to_projective_transforms(
      random_angles, tf.cast(tf.shape(distorted_image)[1], tf.float32), tf.cast(tf.shape(distorted_image)[2], tf.float32)
    ))
  rotate_image = tf.squeeze(distorted_image, [0])
  return rotate_image
 
global_init = tf.global_variables_initializer()
with tf.Session() as sess:
  init = tf.initialize_local_variables()
  sess.run([init, global_init])
  coord = tf.train.Coordinator()
  threads = tf.train.start_queue_runners(coord=coord)
  image = tf.placeholder(shape=(220, 220, 3), dtype=tf.float32)
 
  rotate_image = tf_rotate(image, -np.pi/2, np.pi/2)
  output = sess.run(rotate_image, feed_dict={image:img})
  # print('output:',output)
  plt.imshow(output.astype('uint8'))
  plt.title('rotate image')
  plt.show()

結果如下:

原圖:

使用TensorFlow對圖像進行隨機旋轉的實現示例

隨機旋轉后的圖:

使用TensorFlow對圖像進行隨機旋轉的實現示例

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/qq_26535271/article/details/104030643

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 日韩精品一区二区三区在线 | 一区二区三区 在线 | 国产高清一 | 亚洲天堂av网 | 久久久久久久成人 | 天堂va蜜桃一区二区三区漫画版 | 成人一区二区在线 | 91在线精品一区二区三区 | 欧美久久久久久久久久久久久久 | 午夜爽爽爽 | 免费 成 人 黄 色 | 999国产在线| 免费观看特级毛片 | 成人一级黄色大片 | 午夜影院网站 | 在线精品日韩 | 亚洲毛片在线 | 国产精品美女久久久久久久网站 | 91精品国产色综合久久 | 一区二区av | 国产福利在线视频 | 国产精品久久久久久中文字 | 亚洲欧美精品 | 欧美午夜一区二区福利视频 | 激情综合网激情 | 欧美一区二区三区在线观看视频 | 久久av网 | 中国成人免费视频 | 成人3d动漫一区二区三区91 | 国产乱轮 | 热久久国产 | 国产99久久精品一区二区永久免费 | 日本久久精品视频 | 久久人人爽人人爽人人片av不 | 成人夜晚看av | 日本免费一区二区在线 | 日穴视频在线观看 | 久久久中文 | 欧美日韩一区二区三区在线观看 | 欧美精品一区二区三区四区 | 黄色毛片三级 |