草庐IT

tf_keras

全部标签

python - 使用 tensorflow tf-transform 进行数据规范化

我正在使用Tensorflow对我自己的数据集进行神经网络预测。我做的第一个是在我的计算机中使用一个小数据集的模型。在此之后,我稍微更改了代码,以便使用具有更大数据集的GoogleCloudML-Engine在ML-Engine中实现训练和预测。我正在对Pandas数据框中的特征进行归一化,但这会引入偏斜,我得到的预测结果很差。我真正想要的是使用库tf-transform来规范化图中的数据。为此,我想创建一个函数preprocessing_fn并使用“tft.scale_to_0_1”。https://github.com/tensorflow/transform/blob/maste

python - Keras 提前停止 : Which min_delta and patience to use?

我是深度学习和Keras的新手,我尝试对我的模型训练过程进行的改进之一是利用Keras的keras.callbacks.EarlyStopping回调函数。根据训练我的模型的输出,将以下参数用于EarlyStopping似乎合理吗?EarlyStopping(monitor='val_loss',min_delta=0.0001,patience=5,verbose=0,mode='auto')此外,如果要等待5个连续的时期,其中val_loss的差异小于min_delta0.0001?训练LSTM模型时的输出(没有EarlyStop)运行所有100个epochEpoch1/10010

python - 在有条件的keras中实现自定义损失函数

我需要一些关于keras损失函数的帮助。我一直在使用Tensorflow后端在keras上实现自定义损失函数。我已经在numpy中实现了自定义损失函数,但如果能将其转换为keras损失函数就更好了。损失函数采用数据框和一系列用户ID。如果user_id不同,则同一user_id的欧氏距离为正和负。该函数返回数据帧的标量距离总和。defcustom_loss_numpy(encodings,user_id):#user_id:apandasseriesofusers#encodings:apandasdataframeofencodingsbatch_dist=0foriinrange(

python - 该代码片段在 tensorflow 代码中表示 "tf.logging.set_verbosity(tf.logging.INFO)"是什么意思?

我在很多tensorflow项目中看到了很多对这行代码的使用。这条线在tensorflow中有什么作用? 最佳答案 日志记录级别documentationpage基本上告诉你:如果您将其设置为显示的级别(INFO),则TensorFlow会告诉您所有带有标签INFO(或更重要)的消息。假设您只对WARN或ERROR感兴趣,那么您可以类似地设置tf.logging.set_verbosity(tf.logging.WARN) 关于python-该代码片段在tensorflow代码中表示"t

python - Keras 重命名模型和图层

1)我尝试使用TF后端重命名Keras中的模型和层,因为我在一个脚本中使用多个模型。类模型似乎具有属性model.name,但在更改它时我得到“AttributeError:无法设置属性”。这里的问题是什么?2)此外,我正在使用顺序API,我想给图层命名,这似乎可以使用函数式API,但我没有找到顺序API的解决方案。anonye知道如何为顺序API做吗?更新为2):命名图层有效,尽管它似乎没有记录。只需添加参数名称,例如model.add(Dense(...,...,name="hiddenLayer1")。注意,具有相同名称的图层共享权重! 最佳答案

python - 在 keras 中使用预训练的 gensim Word2vec 嵌入

我在gensim中训练过word2vec。在Keras中,我想用它来制作使用该词嵌入的句子矩阵。由于存储所有句子的矩阵非常占用空间和内存效率。所以,我想在Keras中制作嵌入层来实现这一点,以便它可以用于更多层(LSTM)。你能详细告诉我怎么做吗?PS:和其他题不同,因为我用的是gensim训练word2vec,而不是keras。 最佳答案 假设您有以下需要编码的数据docs=['Welldone!','Goodwork','Greateffort','nicework','Excellent!','Weak','Pooreffor

python - 如何在新图像上使用 .predict_generator() - Keras

我使用ImageDataGenerator和flow_from_directory进行训练和验证。这些是我的目录:train_dir=Path('D:/Datasets/Trell/images/new_images/training')test_dir=Path('D:/Datasets/Trell/images/new_images/validation')pred_dir=Path('D:/Datasets/Trell/images/new_images/testing')ImageGenerator代码:img_width,img_height=28,28batch_size=

python - 函数式 API 中的 Keras Multiply() 层

在新的API变化下,你如何在Keras中进行层的逐元素乘法?在旧的API下,我会尝试这样的事情:merge([dense_all,dense_att],output_shape=10,mode='mul')我试过这个(MWE):fromkeras.modelsimportModelfromkeras.layersimportInput,Dense,Multiplydefsample_model():model_in=Input(shape=(10,))dense_all=Dense(10,)(model_in)dense_att=Dense(10,activation='softmax

python - 连接层的 ValueError(Keras 函数式 API)

经过这里的一些搜索,我仍然找不到解决这个问题的方法。我是Keras的新手,如果有解决方案,我深表歉意,实际上我不明白它与我的问题有何关系。我正在使用Keras2/FunctionalAPI制作一个小型RNN,但我无法让ConcatenateLayer正常工作。这是我的结构:inputSentence=Input(shape=(30,91))sentenceMatrix=LSTM(91,return_sequences=True,input_shape=(30,91))(inputSentence)inputDeletion=Input(shape=(30,1))deletionMatr

python - 通过导出器和 tf.train.write_graph() 保存模型之间的 tensorflow 区别?

保存模型有什么区别使用tensorflowserving中指定的导出器:例如:fromtensorflow.contrib.session_bundleimportexporter#fromtensorflow_serving.session_bundleimportexportersaver=tf.train.Saver(sharded=True)model_exporter=exporter.Exporter(saver)model_exporter.init(sess.graph.as_graph_def(),named_graph_signatures={'inputs':ex