- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 TPU 在 google colab 上进行一些基本的字符分类。我收到以下错误:
InvalidArgumentError: Unsupported data type for TPU: double, caused by output cond_8/Merge:0
我不知道问题是什么,因为我在创建 numpy 数组时使用 float32。我也不知道 cond_8/Merge:0 指的是什么。我加载的输入文件是一个 JSON 数组,表示大量 28x28 灰度图像
[{"label":25,"data":[[[1],[.56720000]...],...]}]
我尝试注释掉除第一个输入层之外的所有层,但问题仍然出现!我的代码是:
import os, re, math, json, shutil, pprint
import PIL.Image, PIL.ImageFont, PIL.ImageDraw
import numpy as np
import json
import tensorflow as tf
from matplotlib import pyplot as plt
from tensorflow.python.platform import tf_logging
from google.colab import drive
print("Tensorflow version " + tf.__version__)
with open('/tmp/encoded.json') as json_file:
data = json.load(json_file)
print("Got data")
images_data = list(map(lambda row: row["data"],data))
label_data = list(map(lambda row: row["label"],data))
print("mapped data")
images_data_tensor = np.asarray(images_data, dtype=np.float32)
label_data_tensor = np.asarray(label_data, dtype=np.float32)
print("converted to tensors")
BATCH_SIZE = 128
N = 24
# This model trains to 99.4% sometimes 99.5% accuracy in 10 epochs (with a batch size of 32)
def create_model():
l = tf.keras.layers
model = tf.keras.Sequential(
[
#l.Reshape(input_shape=(28*28,), target_shape=(28, 28, 1)),
l.Conv2D(input_shape=(28,28,1,), filters=6, kernel_size=3, padding='same', use_bias=False), # no bias necessary before batch norm
l.BatchNormalization(scale=False, center=True), # no batch norm scaling necessary before "relu"
l.Activation('relu'), # activation after batch norm
l.Conv2D(filters=12, kernel_size=6, padding='same', use_bias=False, strides=2),
l.BatchNormalization(scale=False, center=True),
l.Activation('relu'),
l.Conv2D(filters=24, kernel_size=6, padding='same', use_bias=False, strides=2),
l.BatchNormalization(scale=False, center=True),
l.Activation('relu'),
l.Flatten(),
l.Dense(200, use_bias=False),
l.BatchNormalization(scale=False, center=True),
l.Activation('relu'),
l.Dropout(0.5), # Dropout on dense layer only
l.Dense(10, activation='softmax')
])
return model
# set up learning rate decay
lr_decay = tf.keras.callbacks.LearningRateScheduler(lambda epoch: 0.0001 + 0.02 * math.pow(0.5, 1+epoch), verbose=True)
EPOCHS = 10
tpu = None
# Default strategy for GPU/CPU. Note that tensorflow-gpu will need to be installed for GPU to work
strategy = tf.distribute.MirroredStrategy()
try: # TPU detection
tpu = tf.distribute.cluster_resolver.TPUClusterResolver() # Picks up a connected TPU on Google's Colab, ML Engine, Kubernetes and Deep Learning VMs accessed through the 'ctpu up' utility
#tpu = tf.distribute.cluster_resolver.TPUClusterResolver('MY_TPU_NAME') # If auto-detection does not work, you can pass the name of the TPU explicitly (tip: on a VM created with "ctpu up" the TPU has the same name as the VM)
tf.tpu.experimental.initialize_tpu_system(tpu)
strategy = tf.distribute.experimental.TPUStrategy(tpu)
except ValueError:
print('Training on CPU')
with strategy.scope():
trained_model = create_model()
trained_model.compile(optimizer='adam', # learning rate will be set by LearningRateScheduler
loss='categorical_crossentropy',
metrics=['accuracy'])
# print model layers
trained_model.summary()
history = trained_model.fit(x=images_data_tensor,y=label_data_tensor, epochs=EPOCHS, callbacks=[lr_decay])
print(history.history.keys())
最佳答案
当我使用 keras-bert 进行运行分类时,我也在 google colab tpu 中遇到了这个错误。我调低了批量大小和最大长度,然后错误消失了,我不知道为什么。因此您可以尝试调小模型中的批量大小。
关于machine-learning - Colab TPU 错误 - 由输出 cond_8/Merge:0 引起的 InvalidArgumentError : Unsupported data type for TPU: double,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57224105/
例如从 Keras 导入 CIFAR-10 时(使用 from keras.datasets import cifar10 (x_train, y_train), (x_test, y_test) =
我在 gmail 上有两个帐户,并且都同时打开:Account_1@gmail.com 和 Account_2@gmail.com 当我打开 https://colab.research.google
我们可以以任何方式在 google colab 中为 Markdown 单元格启用拼写检查器吗?请帮忙。 最佳答案 我不知道直接在 Google Colaboratory 中执行此操作的任何方法,但是
似乎有很多方法可以从 Colab 访问 Google Drive 上的文件,但没有简单的方法可以将文件从 Google Colab 保存回 Google Drive。 例如,要从 Colab 访问 G
在 Google CoLab 左侧是一个可以打开的 Pane ,显示 Table of Contents , Code snippets , 和 Files . 在 Files Pane 中有一个上传
[较新的编辑]:colab 团队报告说他们已于 2020 年 5 月 27 日更正了该问题。 我已经检查过了 - 现在对我来说可以了。 问题链接:https://github.com/googleco
我一直在尝试读取 google colab 中的文件,它应该将文件作为简单的 JSON 读取,但我什至不能在没有得到 100 个的情况下执行 json.dumps(file)错误 上传文件: impo
training_dataset_file = open('C:/Users/kbg04289/Desktop/mnist_train.csv', 'r') 我尝试了几种方法 比如'用\'制作地址并检
我在 colab 单元中有以下代码: import sklearn.datasets import pandas as pd import numpy as np from sklearn.model
最后我正在研究谷歌合作实验室 我收到了这个数据集celeba,它进入了google驱动器帐户,并且该帐户不是我的帐户,但是我可以访问它 现在,由于互联网问题和驱动器容量,我无法卸载数据集,然后将其上传
德国的大家下午好! Google Colab 和我似乎对什么是可能的、什么是不可能的看法存在分歧......我只是想要一种从单元格内访问所有其他单元格的内容的方法。 我的用例是,我想将当前 Colab
很高兴我可以在 CoLab 中运行 jupyter 笔记本,但我正在疯狂地保存和加载文件。例如,我正在为我的类(class)编写作业,并使用 HTML 标签在其中包含图形。 (我想使用 HTML 而不
我正在使用\begin{equation}.. \end{equation}在 Colab 笔记本中的 Markdown 模式下,我没有像我期望的那样从 Latex 获得方程式编号。 有没有办法解决这
有谁知道是否有办法制作图表,使轴值在 Colab 中悬停时显示? 我找到了几个类似的答案 import matplotlib.pylab as plt import numpy as np f,a =
我写了一个 Langton 的 Ant 代码,我想让动画在 Colab 中运行,直到它被用户停止或在一定数量的帧之后。就像现在一样,它先生成所有的帧,然后将它们编译成动画然后显示。如果有很多帧,则需要
在过去的几个月里,我一直在使用 Google Colab,在连接到驱动器和使用 ! 键入 shell 命令时没有出现任何问题。然而今天突然出现错误,我找不到任何解决方法。 Colab 似乎无法在目录中
我开始使用 google colab 我想从我的笔记本电脑加载一组图像进行处理。 我试过这个: 但是我得到了错误: TypeError: embedded NUL character 那么导入图像的正
即使我将我的 Google 云端硬盘(以及其中的数据集)定义为 google colab,但是当我运行我的代码时,我给出了这个错误:FileNotFoundError: [Errno 2] No su
前言。我正在尝试使用 Google Colab 来教学生 Python。问题是,没有很好的工具来可视化代码执行。我尝试通过将 Python Tutor 与 Google Colab 集成来使用它,即创
我已将多个文件夹从云端硬盘导入到 Google Colab。较小的文件夹在列出目录时工作正常,但当我尝试列出较大文件夹中的目录时,Colab 给我一个错误。 我知道还有其他列出目录的方法,但当我尝试访
我是一名优秀的程序员,十分优秀!