質問編集履歴

2

データセットの準備部分についてのコードを付け加えました。

2017/09/21 11:44

投稿

Sunshine96
Sunshine96

スコア11

test CHANGED
File without changes
test CHANGED
@@ -8,6 +8,118 @@
8
8
 
9
9
  ```python
10
10
 
11
+ # 前データ処理関連
12
+
13
+ import pickle
14
+
15
+ import numpy as np
16
+
17
+ # データセットのダウンロード
18
+
19
+ dtype = 'float16'
20
+
21
+ def unpickle(file):
22
+
23
+ import pickle
24
+
25
+ with open(file, 'rb') as fo:
26
+
27
+ dict = pickle.load(fo, encoding='bytes')
28
+
29
+ return dict
30
+
31
+ batch_name = { 1: "data_batch_1", 2:"data_batch_2", 3: "data_batch_3", 4: "data_batch_4", 5: "data_batch_5"}
32
+
33
+ A = []
34
+
35
+ for (a,b) in batch_name.items():
36
+
37
+ tmp = unpickle("cifar-10-batches-py/{}".format(b))
38
+
39
+ A.append(tmp)
40
+
41
+ tmp = unpickle("cifar-10-batches-py/test_batch")
42
+
43
+ X_test, Y_test = np.array(tmp[b'data'], dtype=dtype), np.array(tmp[b'labels'], dtype=dtype)
44
+
45
+ Y = np.array([])
46
+
47
+ X = np.array([[]])
48
+
49
+ for i in range(5):
50
+
51
+ if i == 0:
52
+
53
+ X = np.array(A[i][b'data'], dtype=dtype)
54
+
55
+ Y = np.array(A[i][b'labels'], dtype=dtype)
56
+
57
+ else:
58
+
59
+ X = np.append(X, np.array(A[i][b'data'], dtype=dtype), axis=0)
60
+
61
+ Y = np.append(Y, np.array(A[i][b'labels'], dtype=dtype))
62
+
63
+ # データセットの整理
64
+
65
+ X_image = X.reshape(-1, 3, 1024).copy()
66
+
67
+ X_max = np.amax(X_image, axis=2, keepdims=True)
68
+
69
+ X_min = np.amin(X_image, axis=2, keepdims=True)
70
+
71
+ X_mean = X_image.mean(axis=2, dtype=dtype, keepdims=True)
72
+
73
+ X_image_st = (X_image - X_mean)/(X_max-X_min)
74
+
75
+ # testデータの方も同様の操作を行う
76
+
77
+ X_test_image = X_test.reshape(-1, 3, 1024).copy()
78
+
79
+ X_test_max = np.amax(X_test_image, axis=2, keepdims=True)
80
+
81
+ X_test_min = np.amin(X_test_image, axis=2, keepdims=True)
82
+
83
+ X_test_mean = X_test_image.mean(axis=2, dtype=dtype, keepdims=True)
84
+
85
+ X_test_image_st = (X_test_image - X_test_mean)/(X_test_max-X_test_min)
86
+
87
+ # RGBの順番にデータが並ぶように結合を直す(ここは勘違い
88
+
89
+ # の可能性があります)
90
+
91
+ X_image_st2 = X_image_st.reshape(-1, 3, 1024,1)
92
+
93
+ X_train = np.concatenate((X_image_st2[:,0], X_image_st2[:,1], X_image_st2[:, 2]), axis=2)
94
+
95
+ X_test_image_st2 = X_test_image_st.reshape(-1,3, 1024,1)
96
+
97
+ X_test = np.concatenate((X_test_image_st2[:,0], X_test_image_st2[:,1], X_test_image_st2[:, 2]), axis=2)
98
+
99
+
100
+
101
+ X_train = X_train.reshape(-1, 1024, 3)
102
+
103
+ X_test = X_test.reshape(-1, 1024, 3)
104
+
105
+ # ラベルデータの前準備(0~9の値からそのインデックスが1になる
106
+
107
+ # ような2次元配列を生成する
108
+
109
+ Y_test2 = np.zeros((10000, 10))
110
+
111
+ Y_train = np.zeros((50000, 10))
112
+
113
+ for i in range(10000):
114
+
115
+ Y_test2[i, int(Y_test[i])] = 1
116
+
117
+ for i in range(50000):
118
+
119
+ Y_train[i, int(Y[i])] = 1
120
+
121
+
122
+
11
123
  import tensorflow as tf
12
124
 
13
125
  x = tf.placeholder(tf.half, shape=[None, 1024, 3])

1

エラー文を追加しました

2017/09/21 11:44

投稿

Sunshine96
Sunshine96

スコア11

test CHANGED
File without changes
test CHANGED
@@ -178,4 +178,10 @@
178
178
 
179
179
  [[Node: mul_1 = Mul[T=DT_HALF, _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_Placeholder_8_0_2, Log_1)]]
180
180
 
181
+
182
+
183
+ InvalidArgumentError: Incompatible shapes: [50,10] vs. [25,10]
184
+
185
+ [[Node: mul_1 = Mul[T=DT_HALF, _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_Placeholder_8_0_2, Log_1)]]
186
+
181
187
  ```