vault backup: 2023-11-09 14:31:31

This commit is contained in:
2023-11-09 14:31:31 +08:00
parent 261f715145
commit fa6e1745e4
3 changed files with 12 additions and 9 deletions

View File

@@ -2,9 +2,9 @@
dataset 會有 `data_batch``label_batch` 這兩個 member分別代表資料與標籤。
可以用 `dataset.batch(32)` 改變 batch size。
還有一些其他的有用function:
- `shuffle(buffer_size)`: 打亂順序
- `shuffle(buffer_size)`: 打亂順序,可參考[[Keras.tensorflow - shuffle#^832c8c]]
- `prefetch(buffer_size)`: 設定預讀的大小
- `map(callback_func)`: 用 callback_func 來處理資料
- `take(N)`: 取出第N筆的批次資料注意這一筆是一個批次資料裡面可能有32筆資料或其他數量看你的 `dataset.batch(N)` 怎麼設定)。
## 用
打亂data的方法請看[[Keras.tensorflow - shuffle]]

View File

@@ -10,7 +10,10 @@ y_data = tf.gather(y_data, idx)
先建立一個跟array一樣大的list然後打亂它再用這個已打亂的list當作索引來建立一個新的data list。
## 2.
## 2. 用 `Dataset.shuffle`
^832c8c
```python
x_train = tf.data.Dataset.from_tensor_slices(x)
y_train = tf.data.Dataset.from_tensor_slices(y)
@@ -31,4 +34,4 @@ 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打亂。
概念跟第一點是一樣的,但是這是先轉成 `tf.data.Dataset`然後把x_train跟y_train都用同樣的seed打亂。