vault backup: 2023-11-09 14:26:01
This commit is contained in:
12
.obsidian/workspace.json
vendored
12
.obsidian/workspace.json
vendored
@@ -41,7 +41,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "markdown",
|
"type": "markdown",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "05. 資料收集/Keras.tensorflow - Dataset.md",
|
"file": "05. 資料收集/Keras.tensorflow - shuffle.md",
|
||||||
"mode": "source",
|
"mode": "source",
|
||||||
"source": true
|
"source": true
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "backlink",
|
"type": "backlink",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "05. 資料收集/Keras.tensorflow - Dataset.md",
|
"file": "05. 資料收集/Keras.tensorflow - shuffle.md",
|
||||||
"collapseAll": false,
|
"collapseAll": false,
|
||||||
"extraContext": false,
|
"extraContext": false,
|
||||||
"sortOrder": "alphabetical",
|
"sortOrder": "alphabetical",
|
||||||
@@ -139,7 +139,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outline",
|
"type": "outline",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "05. 資料收集/Keras.tensorflow - Dataset.md"
|
"file": "05. 資料收集/Keras.tensorflow - shuffle.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -167,7 +167,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "file-properties",
|
"type": "file-properties",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "05. 資料收集/Keras.tensorflow - Dataset.md"
|
"file": "05. 資料收集/Keras.tensorflow - shuffle.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,6 +212,8 @@
|
|||||||
},
|
},
|
||||||
"active": "9ef635642faa0c82",
|
"active": "9ef635642faa0c82",
|
||||||
"lastOpenFiles": [
|
"lastOpenFiles": [
|
||||||
|
"05. 資料收集/Keras.tensorflow - Dataset.md",
|
||||||
|
"05. 資料收集/Keras.tensorflow - shuffle.md",
|
||||||
"01. 個人/01. Daily/2023-11-08(週三).md",
|
"01. 個人/01. Daily/2023-11-08(週三).md",
|
||||||
"01. 個人/01. Daily/2023-11-07(週二).md",
|
"01. 個人/01. Daily/2023-11-07(週二).md",
|
||||||
"01. 個人/01. Daily/2023-11-06(週一).md",
|
"01. 個人/01. Daily/2023-11-06(週一).md",
|
||||||
@@ -238,11 +240,9 @@
|
|||||||
"01. 個人/01. Daily/2023/05",
|
"01. 個人/01. Daily/2023/05",
|
||||||
"01. 個人/01. Daily/2023-10-25(週三).md",
|
"01. 個人/01. Daily/2023-10-25(週三).md",
|
||||||
"00. Inbox/My Mindmap.canvas",
|
"00. Inbox/My Mindmap.canvas",
|
||||||
"05. 資料收集/Keras.tensorflow - Dataset.md",
|
|
||||||
"05. 資料收集/AI.md",
|
"05. 資料收集/AI.md",
|
||||||
"00. Inbox/Habit Tracker.md",
|
"00. Inbox/Habit Tracker.md",
|
||||||
"00. Inbox/台語諺語.md",
|
"00. Inbox/台語諺語.md",
|
||||||
"05. 資料收集/99. templates/日記.md",
|
|
||||||
"00. Inbox/vc-fwUpdate code trace(Meetup).canvas",
|
"00. Inbox/vc-fwUpdate code trace(Meetup).canvas",
|
||||||
"05. 資料收集/Tool Setup/Software/diskstation/share/Tools/字型",
|
"05. 資料收集/Tool Setup/Software/diskstation/share/Tools/字型",
|
||||||
"05. 資料收集/Tool Setup/Software/diskstation/share/Tools",
|
"05. 資料收集/Tool Setup/Software/diskstation/share/Tools",
|
||||||
|
|||||||
34
05. 資料收集/Keras.tensorflow - shuffle.md
Normal file
34
05. 資料收集/Keras.tensorflow - shuffle.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
如果想用同時打亂x_train與y_train,可以參考這2個方法。
|
||||||
|
|
||||||
|
## 1. 用 `tf.random.shuffle`
|
||||||
|
```python
|
||||||
|
indices = tf.range(start=0, limit=tf.shape(x_data)[0], dtype=tf.int32)
|
||||||
|
idx = tf.random.shuffle(indices)
|
||||||
|
x_data = tf.gather(x_data, idx)
|
||||||
|
y_data = tf.gather(y_data, idx)
|
||||||
|
```
|
||||||
|
|
||||||
|
先建立一個跟array一樣大的list,然後打亂它,再用這個已打亂的list當作索引來建立一個新的data list。
|
||||||
|
|
||||||
|
## 2.
|
||||||
|
```python
|
||||||
|
x_train = tf.data.Dataset.from_tensor_slices(x)
|
||||||
|
y_train = tf.data.Dataset.from_tensor_slices(y)
|
||||||
|
|
||||||
|
x_train, y_train = x_train.shuffle(buffer_size=2, seed=2), y_train.shuffle(buffer_size=2, seed=2)
|
||||||
|
dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
|
||||||
|
```
|
||||||
|
|
||||||
|
或者
|
||||||
|
|
||||||
|
```python
|
||||||
|
BF = 2
|
||||||
|
SEED = 2
|
||||||
|
def shuffling(dataset, bf, seed_number):
|
||||||
|
return dataset.shuffle(buffer_size=bf, seed=seed_number)
|
||||||
|
|
||||||
|
x_train, y_train = shuffling(x_train, BF, SEED), shuffling(y_train, BF, SEED)
|
||||||
|
dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
|
||||||
|
```
|
||||||
|
|
||||||
|
概念跟第一點是一樣的,但是這是先轉成 `tf.data.Dataset`,然後把x_train跟y_train都用同樣的seed打亂。
|
||||||
Reference in New Issue
Block a user