質問編集履歴

2

ソースコードの詳細

2019/07/11 07:40

投稿

launcha
launcha

スコア13

test CHANGED
File without changes
test CHANGED
@@ -28,13 +28,97 @@
28
28
 
29
29
 
30
30
 
31
- from tensorflow.python.keras.datasets import mnist
31
+ import numpy as np
32
32
 
33
- (x_train, y_train),(x_test, y_test) = mnist.load_data()
33
+ import matplotlib.pyplot as plt
34
34
 
35
35
 
36
36
 
37
+ from tensorflow.python import keras
38
+
39
+ from tensorflow.python.keras import backend as K
40
+
41
+ from tensorflow.python.keras.models import Model, Sequential
42
+
43
+ from tensorflow.python.keras.layers import Conv2D, Dense, Input, MaxPooling2D, UpSampling2D, Lambda
44
+
45
+ from tensorflow.python.keras.preprocessing.image import load_img, img_to_array, array_to_img, ImageDataGenerator
46
+
47
+
48
+
49
+
50
+
51
+ ls drive/My\ Drive/poke64
52
+
53
+ (x_train, y_train),(x_test, y_test) =?????????????????????????
54
+
55
+
56
+
57
+ /////////CNNで扱いやすい形に変形
58
+
59
+ x_train = x_train.reshape(-1,28,28,1)
60
+
61
+ x_test = x_test.reshape(-1,28,28,1)
62
+
63
+
64
+
65
+ ////////特徴量の正規化
66
+
67
+ x_train = x_train/255.
68
+
69
+ x_test = x_test/255.
70
+
71
+
72
+
73
+ /////////////マスキングノイズ
74
+
75
+ def make_masking_noise_data(data_x,percent=0.1):
76
+
37
- これの自分で用意したデータ版のやり方
77
+ size = data_x.shape
78
+
79
+ masking = np.random.binomial(n=1, p=percent,size=size)
80
+
81
+ return data_x*masking
82
+
83
+
84
+
85
+ x_train_masked = make_masking_noise_data(x_train)
86
+
87
+ x_test_masked = make_masking_noise_data(x_test)
88
+
89
+
90
+
91
+
92
+
93
+ /////////////ガウシアンノイズ
94
+
95
+ def make_gaussian_noise_data(data_x, scale=0.8):
96
+
97
+ gaussian_data_x = data_x + np.random.normal(loc=0, scale=scale, size=data_x.shape)
98
+
99
+ gaussian_data_x = np.clip(gaussian_data_x, 0, 1)
100
+
101
+ return gaussian_data_x
102
+
103
+
104
+
105
+ x_train_gauss = make_gaussian_noise_data(x_train)
106
+
107
+ x_test_gauss = make_gaussian_noise_data(x_test)
108
+
109
+
110
+
111
+ /////////ノイズをかけた画像の表示
112
+
113
+ from IPython.display import display_png
114
+
115
+
116
+
117
+ display_png(array_to_img(x_train[0]))
118
+
119
+ display_png(array_to_img(x_train_gauss[0]))
120
+
121
+ display_png(array_to_img(x_train_masked[0]))
38
122
 
39
123
 
40
124
 

1

誤字

2019/07/11 07:40

投稿

launcha
launcha

スコア13

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,13 @@
28
28
 
29
29
 
30
30
 
31
+ from tensorflow.python.keras.datasets import mnist
31
32
 
33
+ (x_train, y_train),(x_test, y_test) = mnist.load_data()
34
+
35
+
36
+
37
+ これの自分で用意したデータ版のやり方
32
38
 
33
39
 
34
40