Questions tagged «tensorflow2.0»

2
为什么TensorFlow 2比TensorFlow 1慢得多?
许多用户都将其作为切换到Pytorch的原因,但是我还没有找到牺牲/最渴望的实用质量,速度和执行力的理由/解释。 以下是代码基准测试性能,即TF1与TF2的对比-TF1的运行速度提高了47%至276%。 我的问题是:在图形或硬件级别上,什么导致如此显着的下降? 寻找详细的答案-已经熟悉广泛的概念。相关的Git 规格:CUDA 10.0.130,cuDNN 7.4.2,Python 3.7.4,Windows 10,GTX 1070 基准测试结果: UPDATE:禁用每下面的代码不会急于执行没有帮助。但是,该行为是不一致的:有时以图形方式运行会有所帮助,而其他时候其运行速度要比 Eager 慢。 由于TF开发人员没有出现在任何地方,因此我将自己进行调查-可以跟踪相关Github问题的进展。 更新2:分享大量实验结果,并附有解释;应该在今天完成。 基准代码: # use tensorflow.keras... to benchmark tf.keras; used GPU for all above benchmarks from keras.layers import Input, Dense, LSTM, Bidirectional, Conv1D from keras.layers import Flatten, Dropout from keras.models import Model from keras.optimizers import Adam …

10
Tensorflow 2.0-AttributeError:模块'tensorflow'没有属性'Session'
sess = tf.Session()在Tensorflow 2.0环境中执行命令时,出现如下错误消息: Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'tensorflow' has no attribute 'Session' 系统信息: 操作系统平台和发行版:Windows 10 python版本:3.7.1 Tensorflow版本:2.0.0-alpha0(随pip一起安装) 重现步骤: 安装: 点安装-升级点 pip install tensorflow == 2.0.0-alpha0 点安装keras 点安装numpy == 1.16.2 执行: 执行命令:将tensorflow导入为tf 执行命令:sess = tf.Session()

4
警告:tensorflow:sample_weight模式从…强制为['…']
使用.fit_generator()或.fit()将字典传递class_weight=为参数来训练图像分类器。 我从未在TF1.x中遇到错误,但在2.1中,开始训练时得到以下输出: WARNING:tensorflow:sample_weight modes were coerced from ... to ['...'] 强制从...到['...']到底意味着什么? tensorflow的回购中此警告的来源在此处,注释为: 尝试将sample_weight_modes强制转换为目标结构。这隐含地依赖于模型展平其内部表示的输出这一事实。

2
Keras的预测时间不一致
我试图估计我的keras模型的预测时间,并意识到一些奇怪的事情。除了正常情况下相当快外,模型偶尔还需要很长时间才能得出预测。不仅如此,这些时间还增加了模型运行的时间。我添加了一个最小的工作示例来重现该错误。 import time import numpy as np from sklearn.datasets import make_classification from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Flatten # Make a dummy classification problem X, y = make_classification() # Make a dummy model model = Sequential() model.add(Dense(10, activation='relu',name='input',input_shape=(X.shape[1],))) model.add(Dense(2, activation='softmax',name='predictions')) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.fit(X, y, verbose=0, batch_size=20, epochs=100) …

1
Tensorflow无法从dataset.map(mapFn)中的方法获取image.shape
我正在尝试做的tensorflow等效操作torch.transforms.Resize(TRAIN_IMAGE_SIZE),它将最小的图像尺寸调整为TRAIN_IMAGE_SIZE。像这样 def transforms(filename): parts = tf.strings.split(filename, '/') label = parts[-2] image = tf.io.read_file(filename) image = tf.image.decode_jpeg(image) image = tf.image.convert_image_dtype(image, tf.float32) # this doesn't work with Dataset.map() because image.shape=(None,None,3) from Dataset.map() image = largest_sq_crop(image) image = tf.image.resize(image, (256,256)) return image, label list_ds = tf.data.Dataset.list_files('{}/*/*'.format(DATASET_PATH)) images_ds = list_ds.map(transforms).batch(4) 简单的答案在这里:Tensorflow:裁剪图像的最大中央正方形区域 但是当我使用该方法时tf.data.Dataset.map(transforms),我shape=(None,None,3)从内部得到了largest_sq_crop(image)。当我正常调用该方法时,它可以正常工作。

1
每10个时间段tensorflow.keras v2保存模型
我正在使用在tensorflow v2中定义为子模块的keras。我正在使用fit_generator()方法训练模型。我想每10个时间保存一次模型。我该如何实现? 在Keras(不是tf的子模块)中,我可以给出ModelCheckpoint(model_savepath,period=10)。但在TF V2,他们已经改变了这ModelCheckpoint(model_savepath, save_freq)地方save_freq可'epoch'在这种情况下,模型保存每个时间段。如果save_freq为整数,则在处理了许多样本后将保存模型。但我希望在10个时代之后。我该如何实现?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.