我试图在tensorflow中使用条件词,并且我得到了错误:
ValueError: Shapes (1,) and () are not compatible
下面是我使用的抛出错误的代码。它是说错误在条件中。
import tensorflow as tf
import numpy as np
X = tf.constant([1, 0])
Y = tf.constant([0, 1])
BOTH = tf.constant([1, 1])
WORKING = tf.constant(1)
def create_mult_func(tf, amount, list):
def
看看这个例子,我尝试用我的图形处理器来乘以两个tf.int32矩阵。
import tensorflow as tf
matrix1 = tf.constant([[3,3]])
matrix2 = tf.constant([[2],[2]])
with tf.device("/gpu:0"):
product = tf.matmul(matrix1,matrix2)
with tf.Session() as sess:
result = sess.run(product)
print(result)
它与上的示例类似
我得到了输出:
...
I t
我正在尝试创建一个自定义损失函数,以供Keras使用,但我遇到了一些麻烦。下面是这篇文章:Custom loss function in Keras我知道创建函数的语法,但我不熟悉如何使用张量。我用标量填充了yTrue,yPred是实际的预测值。我想取预测值的对数的加权和,按yTrue中的标量加权。当我这样做的时候: def customLoss(yTrue,yPred):
L = 0
for i in range(len(yTrue)):
L += tf.math.scalar_mul(yTrue[i], K.log(yPred[i]
我已经向Keras模型传递了一个自定义的丢失函数,在计算rmse分数之前,我正在尝试inverse_transform我的标签。
我用标准定标器转换了形状(n,1)的标签,其中n表示标签中的记录数。
我的代码
# standardization
lab_scaler2 = StandardScaler().fit(label2)
scaled_lab2 = lab_scaler2.transform(label2)
# custom loss function
from keras import backend as k
def root_mean_squared_error(y_true,
我搞不懂为什么下面的代码返回这个错误消息:
Traceback (most recent call last):
File "/Users/Desktop/TestPython/tftest.py", line 46, in <module>
main(sys.argv[1:])
File "/Users/Desktop/TestPython/tftest.py", line 35, in main
result = tf.while_loop(Cond_f2, Body_f1, loop_vars=loopvars)
F