CoLab设置使用GPU和TPU

##tf2.4.0from tensorflow.python.keras.callbacks import EarlyStoppingfrom tensorflow.python.keras.layers import Embedding, SpatialDropout1D, LSTM, Densefrom tensorflow.python.keras.models import Sequentialimport tensorflow as tfimport os##下面6行为GP...
摘要由CSDN通过智能技术生成

##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://' + 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值