我正在从Keras模型创建一个Tensorflow Estimator。目前,估计器被创建,模型被训练,模型被评估没有问题。然而,在最后一次评估中,由于我使用了FinalExporter接口,模型被导出,并且我得到了一个尺寸不匹配错误: INFO:tensorflow:Performing the final export in the end of training.
INFO:tensorflow:Calling model_fn.
Traceback (most recent call last):
File "/home/austinguo/.../lib/python3
我正在尝试使用谷歌最新版本的TensorFlow中内置的Keras来创建一个示例。这个例子应该能够对一只大象的经典图像进行分类。代码如下所示:
# Import a few libraries for use later
from PIL import Image as IMG
from tensorflow.contrib.keras.python.keras.preprocessing import image
from tensorflow.contrib.keras.python.keras.applications.inception_v3 import InceptionV3
f
numpy.take有类似的吗?我想要从N+1-dimensional数组中形成N-dimensional数组,更准确地说是从具有shape (B, H, W, C)的数组中生成(B, H, W, X, C)数组。
我想,对于我的情况,即使没有这样的一般性操作,也是有解决办法的。但我真的不确定,如果我要编写包含多个中间操作和张量(移位、重复等)的代码,TF是否能够优化它并删除不必要的操作。此外,我认为这样的准则将是不干净和可怕的。
我想添加带有移位值的维度。即对于(H,W)->(H,W,3)维情况索引必须是
[
[[0,0], #[0,-1], may be padding with z
我试图在tensorflow模型中添加预处理层,但无法正确地使用tf.keras.layers.Reshape。
我有一些以前的预处理层,这些图层会给TensorShape([50, 50, 3])形状的tensorflow张量带来一幅numpy图像。
我试图将这些预处理层连接到模型的第一层是一个卷积层,它需要一个四维的输入。当我调用维数Tensorshape([50,50,3])张量上的模型时,有三个维度,我得到了错误:
Input 0 of layer "Conv1" is incompatible with the layer: expected min_ndim=4,
完全错误是
WARNING:tensorflow:Model was constructed with shape (None, None, 6) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, 6), dtype=tf.float32, name='dense_input'), name='dense_input', description="created by layer 'dense_input'"), but it was called on a
由于某些原因,在TF 2中使用gather时,我得到了不同的张量尺寸:
当我使用张量作为索引向量时,第一个维度变成None,第一个维度变成len(indices) (正如它应该的那样),其中‘index’是常规的Python列表。
这种情况只发生在急切模式下(例如,在自定义丢失函数中)
(使用boolean_mask时也会发生同样的情况)
编辑:下面的代码再现了TF-2.7.0和Python3.8.10的问题
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import Model
from
我想使用度量学习自定义损失函数来训练Python和Keras中的神经网络。损失使相似输入的输出距离最小化,使不同输入之间的距离最大化。考虑类似投入的部分是:
# function to create a pairwise similarity matrix, i.e
# L[i,j] == 1 for similar samples i, j and 0 otherwise
def build_indicator_matrix(y_, thr=0.1):
# y_: contains the labels of the samples,
# samples are simila
我在努力解决分类问题。我不知道为什么我会犯这个错误:
ValueError: Input 0 of layer sequential_9 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, None, None]
这是主要代码:
model = createModel()
filesPath=getFilesPathWithoutSeizure(i, indexPat)
history=model.fit_generator(generate_array
目前正在构建一个ReactNative应用程序来使用TensorFlow反应本机库来检测对象。
没有任何经验的TensorFlow,我遵循的例子和指南,设置世博会相机与临时的tfjs-反应本地。()
<TensorCamera
// Standard Camera props
style={styles.camera}
type={Camera.Constants.Type.back}
// Tensor related props
cameraTextureHeight
我试图通过构建来学习人工智能算法。我发现了一个关于堆栈溢出的问题,即。我复制了这段代码来试一试,然后把它修改成这样。
import numpy as np
import tensorflow as tf
from tensorflow import keras as keras
from tensorflow.keras.layers import Dense, Activation
from tensorflow.keras.models import Sequential
from sklearn.model_selection import train_test_split
import
我正在尝试keras.layers.LSTM,下面的代码可以工作。
#!/usr/bin/python3
import tensorflow as tf
import numpy as np
from tensorflow import keras
data = np.array([1, 2, 3]).reshape((1, 3, 1))
x = keras.layers.Input(shape=(3, 1))
y = keras.layers.LSTM(10)(x)
model = keras.Model(inputs=x, outputs=y)
print (model.predi
我正在尝试为学校的一个项目写一个入门代码,这是我第一次使用机器学习或类似的东西,所以如果有任何帮助,我将非常感激。我尝试使用一本书作为我的开始,并严格遵循代码,并理解几乎所有的东西。但是我还不太了解如何调试我的程序,我已经检查了这个问题的堆栈溢出,但我仍然不太明白如何解决这个问题。 import tensorflow as tf
import numpy as np
from google.colab import files
from keras.preprocessing import image
import random
from tensorflow.keras.optimizer
我遇到一个问题,链接tf.gather()索引会产生以下警告:
/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gradients.py:90: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
"Converting sparse IndexedSlices to a dense Tenso
我从一篇研究论文中复制了一个深层次的CNN。当我最初构建模型时,我假设批处理的大小是1。但是,现在我已经了解了更多关于批处理大小的知识,我想使用40的批处理大小。
这是
这是一个非常深的网络,因此我将在下面展示一个更基本的项目版本:
x = tf.placeholder(tf.float32, shape=[None, 7168])
y_ = tf.placeholder(tf.float32, shape=[None, 7168, 3])
#MANY CONVOLUTIONS OMITTED HERE
#one of many transpose convolutions, the 40
我正在尝试访问图形卷积网络中间层的输出,model.predict抛出了输入值的InvalidArgument错误,因为model.fit在相同的输入下工作得很好。 这是我的代码,它使用了由spektral库提供的来自OGB的'CORA‘引用数据集,该库为图卷积网络提供了算法和示例。我的代码基于同一个库here中的一个示例 from spektral.datasets import citation
from spektral.layers import GraphConv
import tensorflow as tf
from tensorflow.keras.models im
我想对TensorFlow张量执行以下索引操作。在TensorFlow中,获得b和c作为输出的等效操作应该是什么?虽然tf.gather_nd文档有几个例子,但我无法生成等效的indices张量来获得这些结果。
import tensorflow as tf
import numpy as np
a=np.arange(18).reshape((2,3,3))
idx=[2,0,1] #it can be any validing re-ordering index list
#These are the two numpy operations that I want to do in