##tf2.4.0
from tensorflow.python.keras.callbacks import EarlyStopping
from tensorflow.python.keras.layers import Embedding, SpatialDropout1D, LSTM, Dense
from tensorflow.python.keras.models import Sequential
import tensorflow as tf
import os
##下面6行为GPU设置,若用GPU,则用这6行,其他的就不用了了
# gpus = tf.config.list_physical_devices("GPU")
# print(gpus)
# if gpus:
# gpu0 = gpus[0] # 如果有多个GPU,仅使用第0个GPU
# tf.config.experimental.set_memory_growth(gpu0, True) # 设置GPU显存用量按需使用
# tf.config.set_visible_devices([gpu0], "GPU")
#加载数据
with open('w2v1000.pkl', 'rb') as f:
dict = pickle.load(f)
X = dict['X']
Y = dict['Y']
#TPU设置代码,以下全为TPU的设置,需要注释掉上面GPU设置的6行,所有代码原封不动照搬即可,只需要
#在模型编译print语句后把自己模型给替换即可。
tf.keras.backend.clear_session()
resolver = tf.distribute.cluster_resolver.TPUClusterResolver(tpu='grpc://' +
CoLab设置使用GPU和TPU
最新推荐文章于 2022-09-01 20:09:21 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)