Skip to content

Commit 4757803

Browse files
committed
shuffle data before training
Again, it is my misunderstand about `model.fit(shuffle=True)`, it means "Whether to shuffle the samples at each epoch" ,but not "shuffle the samples before spliting them into train-set and val-set".
1 parent c040753 commit 4757803

File tree

1 file changed

+6
-0
lines changed
  • DeepLearning Tutorials/keras_usage

1 file changed

+6
-0
lines changed

DeepLearning Tutorials/keras_usage/cnn.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
from keras.utils import np_utils, generic_utils
1919
from six.moves import range
2020
from data import load_data
21+
import random
2122

2223

2324

2425

2526
#加载数据
2627
data, label = load_data()
28+
#打乱数据
29+
index = [i for i in range(len(data))]
30+
random.shuffle(index)
31+
data = data[index]
32+
label = label[index]
2733
print(data.shape[0], ' samples')
2834

2935
#label为0~9共10个类别,keras要求格式为binary class matrices,转化一下,直接调用keras提供的这个函数

0 commit comments

Comments
 (0)