- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用自动编码器开发图像着色器。有 13000 张训练图像。如果我使用 tf.data,每个 epoch 大约需要 45 分钟,如果我使用 tf.utils.keras.Sequence 大约需要 25 分钟。但是,使用 Sequence 存在死锁的风险。如何改进 tf.data?我尝试了一些东西,但它们似乎没有任何改善。
tf.data 1
image_path_list = glob.glob('datasets/imagenette/*')
data = tf.data.Dataset.list_files(image_path_list)
def tf_rgb2lab(image):
im_shape = image.shape
[image,] = tf.py_function(color.rgb2lab, [image], [tf.float32])
image.set_shape(im_shape)
return image
def preprocess(path):
image = tf.io.read_file(path)
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.convert_image_dtype(image, tf.float32)
image = tf.image.resize(image, [224, 224])
image = tf_rgb2lab(image)
L = image[:,:,0]/100.
ab = image[:,:,1:]/128.
input = tf.stack([L,L,L], axis=2)
return input, ab
train_ds = data.repeat().map(preprocess, AUTOTUNE).batch(32).prefetch(AUTOTUNE)
tf.data 2
AUTOTUNE = tf.data.experimental.AUTOTUNE
def tf_rgb2lab(image):
im_shape = image.shape
[image,] = tf.py_function(color.rgb2lab, [image], [tf.float32])
image.set_shape(im_shape)
return image
def split_for_feed(image):
L = image[:,:,:,0]/100.
ab = image[:,:,:,1:]/128.
input = tf.stack([L,L,L], axis=-1)
return input, ab
def read_images(path):
image = tf.io.read_file(path)
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.convert_image_dtype(image, tf.float32)
image = tf.image.resize(image, [224, 224])
image = tf_rgb2lab(image)
return image
data2 = data.repeat().map(read_images, AUTOTUNE).batch(32)
train_ds = data2.map(split_for_feed, AUTOTUNE).prefetch(AUTOTUNE)
序列
class ImageGenerator(tf.keras.utils.Sequence):
def __init__(self, image_filenames, batch_size):
self.image_filenames = image_filenames
self.batch_size = batch_size
def __len__(self):
return math.ceil(len(self.image_filenames) / self.batch_size)
def __getitem__(self, idx):
batch = self.image_filenames[idx * self.batch_size : (idx + 1) * self.batch_size]
X_batch = []
y_batch = []
for file_name in batch:
file_name = 'datasets/imagenette/' + file_name
try:
color_image = transform.resize(io.imread(file_name),(224,224))
lab_image = color.rgb2lab(color_image)
L = lab_image[:,:,0]/100.
ab = lab_image[:,:,1:]/128.
X_batch.append(np.stack((L,L,L), axis=2))
y_batch.append(ab)
except:
pass
return np.array(X_batch), np.array(y_batch)
最佳答案
如果您的数据适合内存,请尝试缓存预处理。代替
train_ds = data.repeat().map(preprocess, AUTOTUNE).batch(32).prefetch(AUTOTUNE)
做
train_ds = data.map(preprocess, AUTOTUNE).batch(32).cache().repeat().prefetch(AUTOTUNE)
这样您只需解析每个文件一次,而不是重复解析。
关于tensorflow - tf.data 或 tf.keras.utils.Sequence。提高 tf.data 的效率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63113565/
给定一个 Sequence of Sequences 类型,如何将其转换为单个扁平化 Sequence 类型?考虑以下 Ceylon 代码: Integer[] range(Integer max)
出于学习目的,我正在尝试使用 F# 以序列形式运行模拟。从一系列随机数开始,如果状态不依赖于先前的状态,map 是生成状态序列的直接方法。我遇到问题的地方是当我尝试做类似的事情时: State(i+1
我正在 DynamoDB 上开发论坛。 有一个帖子表,其中包含线程中的所有帖子。我需要对帖子中的顺序有一个概念,即我需要知道哪个帖子先出现,哪个后出现。 我的服务将在分布式环境中运行。 我不确定使用时
我正在 DynamoDB 上开发论坛。 有一个帖子表,其中包含线程中的所有帖子。我需要对帖子中的顺序有一个概念,即我需要知道哪个帖子先出现,哪个后出现。 我的服务将在分布式环境中运行。 我不确定使用时
在 Z3 中,它支持 String 和 Sequence。但是 Z3py 是否也支持它们,或者我们必须使用 Python 中的字符串或列表?从最新的版本来看,新版本好像确实支持了String和Sequ
我是 Clojure 世界的新手,我遇到了一个问题。我得到了一个 LazySeq,看起来像这样(实际上更长) values = (("Brand1" "0") ("Brand2" "15") ("Br
我正在开发一个用于文本生成的序列到序列模型 ( paper )。我没有在解码器端使用“教师强制”,即 t0 时解码器的输出被馈送到 t1 时解码器的输入。 现在,实际上,解码器(LSTM/GRU)的输
Rust 中的规则是什么,类似于这里描述的规则http://en.cppreference.com/w/cpp/language/eval_order对于 C++? 目前我凭经验发现, 1) 函数的参
我当前的代码: import re from Bio.Seq import Seq def check_promoter(binding_element,promoter_seq): promoter
您好,此代码旨在存储使用 open cv 绘制的矩形的坐标,并将结果编译为单个图像。 import numpy as np import cv2 im = cv2.imread('1.jpg') im
在我的程序中,我有一个正则表达式,它确保输入字符串至少有一个字母和一个数字字符,并且长度在 2 到 10 之间。 Pattern p = Pattern.compile("^(?=.*\\d)(?=.
我正在查看 Google 的免费机器学习速成类(class),并尝试根据他们类(class)的第一部分制作一个预测模型。但是,在输入函数中,有一个字典,我不断收到此错误, in my_input_fn
我想使用 Boost 的 any_range 来处理多个异构数据范围。我的数据范围类型称为 fusion vector ,例如: typedef vector TypeSequence 鉴于这样的类型
我正在使用 SimpleJdbcInsert 作为, SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource).with
我正在尝试通过从我的数据创建 .phy 文件来创建系统发育树。 我有一个数据框 ndf= ESV trunc 1 esv1 TACGTAGGTG... 2 esv2 TACGGAGGGT... 3 e
这可能真的很简单,但我正处于 Rx 学习曲线的底部。我花了几个小时阅读文章、观看视频和编写代码,但我似乎对一些看起来应该非常简单的事情有心理障碍。 我正在从串行端口收集数据。我已使用 Observab
我正在将一些模块从 v8 迁移到 v10,我有这个模型: class SearchInfoPartnerSeniat(models.TransientModel): _name = "search.i
我尝试添加一个新的“自定义”序列到我的Marten DB中,以获取新用户的用户ID(在注册过程中)。。后来,我能够访问下一个序列值,如下所示:。问题出在上面的代码中:在第一次运行时:将userid_s
我在 rosettacode 遇到了这个代码 my @pascal = [1], { [0, |$_ Z+ |$_, 0] } ... Inf; .say for @pascal[^4]; # ==>
我不明白为什么这个程序有效: my $supply = Supply.interval: 1; react { whenever $supply { put "Got $^a" }
我是一名优秀的程序员,十分优秀!