質問編集履歴
2
データセットの準備部分についてのコードを付け加えました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,6 +3,62 @@
|
|
3
3
|
意味のわかる方、回答お願いします。
|
4
4
|
|
5
5
|
```python
|
6
|
+
# 前データ処理関連
|
7
|
+
import pickle
|
8
|
+
import numpy as np
|
9
|
+
# データセットのダウンロード
|
10
|
+
dtype = 'float16'
|
11
|
+
def unpickle(file):
|
12
|
+
import pickle
|
13
|
+
with open(file, 'rb') as fo:
|
14
|
+
dict = pickle.load(fo, encoding='bytes')
|
15
|
+
return dict
|
16
|
+
batch_name = { 1: "data_batch_1", 2:"data_batch_2", 3: "data_batch_3", 4: "data_batch_4", 5: "data_batch_5"}
|
17
|
+
A = []
|
18
|
+
for (a,b) in batch_name.items():
|
19
|
+
tmp = unpickle("cifar-10-batches-py/{}".format(b))
|
20
|
+
A.append(tmp)
|
21
|
+
tmp = unpickle("cifar-10-batches-py/test_batch")
|
22
|
+
X_test, Y_test = np.array(tmp[b'data'], dtype=dtype), np.array(tmp[b'labels'], dtype=dtype)
|
23
|
+
Y = np.array([])
|
24
|
+
X = np.array([[]])
|
25
|
+
for i in range(5):
|
26
|
+
if i == 0:
|
27
|
+
X = np.array(A[i][b'data'], dtype=dtype)
|
28
|
+
Y = np.array(A[i][b'labels'], dtype=dtype)
|
29
|
+
else:
|
30
|
+
X = np.append(X, np.array(A[i][b'data'], dtype=dtype), axis=0)
|
31
|
+
Y = np.append(Y, np.array(A[i][b'labels'], dtype=dtype))
|
32
|
+
# データセットの整理
|
33
|
+
X_image = X.reshape(-1, 3, 1024).copy()
|
34
|
+
X_max = np.amax(X_image, axis=2, keepdims=True)
|
35
|
+
X_min = np.amin(X_image, axis=2, keepdims=True)
|
36
|
+
X_mean = X_image.mean(axis=2, dtype=dtype, keepdims=True)
|
37
|
+
X_image_st = (X_image - X_mean)/(X_max-X_min)
|
38
|
+
# testデータの方も同様の操作を行う
|
39
|
+
X_test_image = X_test.reshape(-1, 3, 1024).copy()
|
40
|
+
X_test_max = np.amax(X_test_image, axis=2, keepdims=True)
|
41
|
+
X_test_min = np.amin(X_test_image, axis=2, keepdims=True)
|
42
|
+
X_test_mean = X_test_image.mean(axis=2, dtype=dtype, keepdims=True)
|
43
|
+
X_test_image_st = (X_test_image - X_test_mean)/(X_test_max-X_test_min)
|
44
|
+
# RGBの順番にデータが並ぶように結合を直す(ここは勘違い
|
45
|
+
# の可能性があります)
|
46
|
+
X_image_st2 = X_image_st.reshape(-1, 3, 1024,1)
|
47
|
+
X_train = np.concatenate((X_image_st2[:,0], X_image_st2[:,1], X_image_st2[:, 2]), axis=2)
|
48
|
+
X_test_image_st2 = X_test_image_st.reshape(-1,3, 1024,1)
|
49
|
+
X_test = np.concatenate((X_test_image_st2[:,0], X_test_image_st2[:,1], X_test_image_st2[:, 2]), axis=2)
|
50
|
+
|
51
|
+
X_train = X_train.reshape(-1, 1024, 3)
|
52
|
+
X_test = X_test.reshape(-1, 1024, 3)
|
53
|
+
# ラベルデータの前準備(0~9の値からそのインデックスが1になる
|
54
|
+
# ような2次元配列を生成する
|
55
|
+
Y_test2 = np.zeros((10000, 10))
|
56
|
+
Y_train = np.zeros((50000, 10))
|
57
|
+
for i in range(10000):
|
58
|
+
Y_test2[i, int(Y_test[i])] = 1
|
59
|
+
for i in range(50000):
|
60
|
+
Y_train[i, int(Y[i])] = 1
|
61
|
+
|
6
62
|
import tensorflow as tf
|
7
63
|
x = tf.placeholder(tf.half, shape=[None, 1024, 3])
|
8
64
|
x_image = tf.reshape(x, [-1, 32, 32, 3]) # バッチ数、縦、横、チャンネル数
|
1
エラー文を追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -88,4 +88,7 @@
|
|
88
88
|
```python
|
89
89
|
InvalidArgumentError: Incompatible shapes: [50,10] vs. [25,10]
|
90
90
|
[[Node: mul_1 = Mul[T=DT_HALF, _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_Placeholder_8_0_2, Log_1)]]
|
91
|
+
|
92
|
+
InvalidArgumentError: Incompatible shapes: [50,10] vs. [25,10]
|
93
|
+
[[Node: mul_1 = Mul[T=DT_HALF, _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_Placeholder_8_0_2, Log_1)]]
|
91
94
|
```
|