我正在使用tf急切模式,并试图创建一个GAN模型。为此,我创建了一个类,如下所示。我试着具体地发送数组,在keras问题中找到了,但这也不起作用吗?
class vanillaGAN(tf.keras.Model):
"""Vanilla GAN"""
def __init__(self, noise_dims, input_dims):
"""Define all layer used in network"""
super(vanillaGAN,
我正在尝试理解嵌入层是如何与掩蔽一起工作的(从序列到序列回归)。
这段简单的代码失败,错误为:AttributeError: 'Embedding' object has no attribute 'get_shape'。这似乎是真的,但我不知道如何解决它。有什么提示吗?
import numpy as np
from keras.layers import Input, Dense, LSTM
from keras.layers.embeddings import Embedding
from keras.layers.merge import Concate
我有一个名为e的常规keras模型,我想在我的自定义丢失函数中比较它对y_pred和y_true的输出。
from keras import backend as K
def custom_loss(y_true, y_pred):
return K.mean(K.square(e.predict(y_pred)-e.predict(y_true)), axis=-1)
我得到了错误:AttributeError: 'Tensor' object has no attribute 'ndim',这是因为y_true和y_pred都是张量对象,keras.
我有个阵列。我的任务是打印出数组,以及数组的形状、大小、项大小、尺寸和数据类型名称。输出应该是一个文本文件-每个属性都应该在一个新的行上。
当我尝试使用以下代码时,会得到错误:
File "<ipython-input-76-f4d4f45285be>", line 1, in <module>
print(a.shape)
AttributeError: 'NoneType' object has no attribute 'shape'
我尝试了两个选项,打开一个文本文件和np.savetxt。两者似乎都
系统信息:
3.6.10tensorflow keras 2.3.1pip 20.2.2python 2.3.0
我正在研究一个暹罗算法,在后端。我导入了keras后端,如下所示,它显示了上面的属性错误。这样做的原因是什么,以及如何避免这一问题?
import tensorflow.python.keras.backend as K
AttributeError:模块'tensorflow‘没有属性'python'
我必须编写自己的自定义丢失函数,这些函数可以在Keras中接受不同的输入,而不是y_true和y_pred参数。在阅读了一些变通方法之后,我决定使用内部函数如下:
from keras import backend as K
lambda_prn_regr = 0.6
lambda_prn_vis = 0.2
lambda_prn_class = 0.2
epsilon = 1e-4
# Person loss
def prn_loss_cls(y_true, y_pred):
def prn_loss_cls_fixed_num(y_true, y_pred):
是否有可能用来自Keras的现有激活来绘制我定义的激活函数?我试过这样做:
import keras
from keras import backend as K
import numpy as np
import matplotlib.pyplot as plt
# Define swish activation:
def swish(x):
return K.sigmoid(x) * x
x = np.linspace(-10, 10, 100)
plt.plot(x, swish(x))
plt.show()
但是上面的代码会产生一个错误:AttributeError: &
我正在尝试构建一个只有一个层的自动编码器:
from keras import backend as K
def cost2(y_true, y_pred):
print "shapes:", model.get_weights()[0].shape
yy = K.dot( y_pred, model.get_weights()[0].T )
return np.sum((y_true - yy)**2)
x = Input(shape=(original_dim,))
y = Dense(latent_dim)(x)
model = Model(i
我正在尝试在Azure笔记本中导入MobilenetV2,但是我得到了一个错误。请注意,我可以通过本地机器上的木星笔记本导入运行相同命令的模型。
import tensorflow as tf
from tensorflow import keras
model = tf.keras.applications.MobileNetV2()
错误日志如下所示
---------------------------------------------------------------------------
AttributeError Tr
当调用keras model.fit()时,我将得到以下错误。
AttributeError: 'RepeatDataset' object has no attribute 'ndim'
我使用的是TensorFlow 1.7和Keras。不幸的是,I必须使用TF-1.7。知道怎么回事吗?代码,改编自tensorflow演示:
import tensorflow as tf
from IPython import embed
from tensorflow.python import keras
from tensorflow.python.keras imp
下面是我写的代码:
from keras.callbacks import History
history = History()
# Create model - 3 layers. First layer 128 neurons, second layer 64 neurons and 3rd output layer contains number of neurons
# equal to number of intents to predict output intent with softmax
model = Sequential()
model.add(LSTM(128,
在运行BERT模型时收到错误。至此,代码成功运行。我收到的错误是形状:'str‘对象没有’AttributeError‘属性。代码之前的上一步是创建自定义数据生成器。使用这一点,创建了模型。为了提供上下文,我使用的模型在网站https://keras.io/examples/nlp/semantic_similarity_with_bert/上找到,我用它来解释我自己的数据。 from ipywidgets import IntProgress
strategy = tf.distribute.MirroredStrategy()
with strategy.scope():
为了将VGG16网络用于回归任务,我以以下方式对其进行了扩展:
keras.applications.vgg16.VGG16(input_tensor=input_tensor, include_top=False)
x = model.output
x = Flatten()(x)
x = Dense(1024, activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(512,activation='relu')(x)