请在下面找到将图像分类为 2 类的代码,我正在尝试使用 Kaggle TPU 执行这些代码。你能帮忙解决这里的问题吗?我遵循了 Kaggle 网站上的指南来使用 GPU,但仍然没有运气。
下面是代码生成的错误堆栈
import tensorflow as tf
tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
tpu_strategy = tf.distribute.experimental.TPUStrategy(tpu)
print(tpu_strategy)
# save the final model to file
from keras.applications.vgg16 import VGG16
from keras.models import Model
from keras.layers import Dense
from keras.layers import Flatten
from keras.preprocessing.image import ImageDataGenerator
# define cnn model
def define_model():
with tpu_strategy.scope():
# load model
model = VGG16(include_top=False, input_shape=(224, 224, 3))
# mark loaded layers as not trainable
for layer in model.layers:
layer.trainable = …
Run Code Online (Sandbox Code Playgroud)