[英]Tensorflow model.fit doesn't start
我們有以下tensorflow
model 配件代碼。
data, labels, data_test, labels_test = get_data_and_labels()
model = tf.keras.models.Sequential(
[
tf.keras.layers.InputLayer(input_shape=(data.shape[1],)),
tf.keras.layers.Dense(64),
tf.keras.layers.Activation(tf.keras.activations.relu, name=f"relu1"),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(64),
tf.keras.layers.Activation(tf.keras.activations.relu, name=f"relu2"),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(1),
tf.keras.layers.Activation(tf.keras.activations.tanh, name=f"tanh"),
]
)
optimizer = tf.optimizers.Adam(learning_rate=1e-5)
model.compile(
optimizer,
tf.keras.losses.mean_squared_error,
metrics=['cosine_similarity', 'logcosh']
)
cp_callback = tf.keras.callbacks.ModelCheckpoint(
filepath="model_checkpoints/cp-{epoch:04d}.ckpt", save_weights_only=True, verbose=1
)
model.fit(
data,
labels,
# batch_size=64,
epochs=200,
callbacks=[cp_callback],
validation_data=(data_test, labels_test),
)
我試圖在沒有GPU
(我們目前沒有)的情況下安裝它,但是當我運行代碼時,我唯一得到的是:
2021-04-28 10:06:58.123786: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-04-28 10:06:58.126582: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
它像這樣卡住了幾個小時,沒有額外的錯誤。 我們有大約 140 萬條記錄,我們在 Windows 10 上運行。
只是因為缺少GPU
而卡住了嗎? 還是我們應該做點別的? 任何幫助都會受到重視。
因此,問題不在於實際訓練,而在於訓練測試記錄的拆分。
以下是我們最初的做法:
def split_train_test(data: pd.DataFrame, label: pd.DataFrame, test_part: float = 0.3):
size = data.shape[0]
test_size = int(size * test_part)
all_indices = list(range(size))
test_indices = list(np.random.choice(all_indices, size=test_size))
test_indices.sort()
train_indices = [i for i in all_indices if i not in test_indices]
return (
data.iloc[train_indices, :].to_numpy(),
label.iloc[train_indices].to_numpy(),
data.iloc[test_indices, :].to_numpy(),
label.iloc[test_indices].to_numpy(),
)
這就是我們現在的做法:
def split_train_test(df: pd.DataFrame, test_part: float = 0.3):
df = df.sample(frac=1)
size = df.shape[0]
test_size = int(size * test_part)
data, label = df.drop(PREDICTION_FIELD, axis=1), df[PREDICTION_FIELD]
return (
data.iloc[:-test_size, :].to_numpy(),
label.iloc[:-test_size].to_numpy(),
data.iloc[-test_size:, :].to_numpy(),
label.iloc[-test_size:].to_numpy(),
)
這解決了性能問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.