小编Sam*_*cem的帖子

tf.data.Dataset:不得为给定的输入类型指定 `batch_size` 参数

我使用的Talos和谷歌colab TPU运行的超参数调整Keras模型。请注意,我使用的是 Tensorflow 1.15.0 和 Keras 2.2.4-tf。

import os
import tensorflow as tf
import talos as ta
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import Adam
from sklearn.model_selection import train_test_split

def iris_model(x_train, y_train, x_val, y_val, params):

    # Specify a distributed strategy to use TPU
    resolver = tf.contrib.cluster_resolver.TPUClusterResolver(tpu='grpc://' + os.environ['COLAB_TPU_ADDR'])
    tf.contrib.distribute.initialize_tpu_system(resolver)
    strategy = tf.contrib.distribute.TPUStrategy(resolver)

    # Use the strategy to create and compile a Keras model
    with strategy.scope():
      model = Sequential()
      model.add(Dense(32, input_shape=(4,), activation=tf.nn.relu, …
Run Code Online (Sandbox Code Playgroud)

keras tensorflow google-colaboratory google-cloud-tpu talos

12
推荐指数
1
解决办法
5983
查看次数

Google Colab:为什么 CPU 比 TPU 快?

我正在使用 Google colab TPU来训练一个简单的Keras模型。去掉分布式策略,在CPU上运行相同的程序比TPU快得多。这怎么可能?

import timeit
import os
import tensorflow as tf
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import Adam

# Load Iris dataset
x = load_iris().data
y = load_iris().target

# Split data to train and validation set
x_train, x_val, y_train, y_val = train_test_split(x, y, test_size=0.30, shuffle=False)

# Convert train data type to use TPU 
x_train = x_train.astype('float32')
x_val …
Run Code Online (Sandbox Code Playgroud)

deep-learning keras tensorflow google-colaboratory google-cloud-tpu

4
推荐指数
2
解决办法
4942
查看次数