草庐IT

python - Keras model.fit() 与 tf.dataset API + validation_data

所以我通过以下代码让我的keras模型与tf.Dataset一起工作:#Initializebatchgenerators(returnstf.Dataset)batch_train=build_features.get_train_batches(batch_size=batch_size)#CreateTensorFlowIteratorobjectiterator=batch_train.make_one_shot_iterator()dataset_inputs,dataset_labels=iterator.get_next()#CreateModellogits=.....

python - 使用分布式 TensorFlow 学习 Keras 模型

我在两台不同的机器上安装了两个GPU。我想构建一个集群,让我可以通过同时使用两个GPU来学习Keras模型。Keras博客在分布式训练部分和链接官方Tensorflow文档中显示了两段代码。我的问题是我不知道如何学习我的模型并将Tensorflow文档中报告的内容付诸实践。比如我想在多个GPU的集群上执行下面的代码怎么办?#Forasingle-inputmodelwith2classes(binaryclassification):model=Sequential()model.add(Dense(32,activation='relu',input_dim=100))model.a

python - Keras 中的自定义加权损失函数,用于对每个元素进行加权

我正在尝试创建一个简单的加权损失函数。比如说,我的输入维度是100*5,输出维度也是100*5。我还有一个相同维度的权重矩阵。类似下面的内容:importnumpyasnptrain_X=np.random.randn(100,5)train_Y=np.random.randn(100,5)*0.01+train_Xweights=np.random.randn(*train_X.shape)定义自定义损失函数defcustom_loss_1(y_true,y_pred):returnK.mean(K.abs(y_true-y_pred)*weights)定义模型fromkeras.l

python - 在tensorflow代码中使用keras层

假设我有一个简单的神经网络,其中有一个输入层和一个用tensorflow编程的卷积层:#InputLayerinput_layer=tf.reshape(features["x"],[-1,28,28,1])#ConvolutionalLayer#1conv1=tf.layers.conv2d(inputs=input_layer,filters=32,kernel_size=[5,5],padding="same",activation=tf.nn.relu)我省略了功能的网络定义的任何其他部分。如果我想在这个卷积层之后添加一个LSTM层,我必须制作卷积层TimeDistribute

python - keras flow_from_directory 超过或欠采样一个类

我正在尝试使用Keras解决二元分类问题,使用ImageDataGenerator.flow_from_directory方法生成批处理。但是,我的类非常不平衡,比如一个类比另一个多8倍或9倍,导致模型在为每个示例预测相同的输出类时卡住。有没有一种方法可以将flow_from_directory设置为在每个时期从我的小类过采样或从我的大类欠采样?目前,我刚刚在小类为每个图像创建了多个副本,但我希望有更多的灵active。 最佳答案 使用当前版本的Keras-仅使用Keras内置方法无法平衡您的数据集。flow_from_direct

python - 无法导入 keras.layers.Merge

我想在Keras中合并两个LSTM模型。我见过很多导入Merge的例子:fromkeras.layersimportMerge执行此操作时,出现导入错误。ImportError:无法导入名称“Merge”。是否有一些重构,现在合并在别处? 最佳答案 从keras2开始,模块keras.layers.merge没有通用的公共(public)Merge层。相反,您应该直接导入keras.layers.Add或keras.layers.Concatenate等子类(或它们具有相同名称小写的功能接口(interface):keras.lay

python - 如何解释 Keras 中 LSTM 层中的权重

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭3年前。Improvethisquestion我目前正在使用LSTM层训练用于天气预报的递归神经网络。网络本身非常简单,大致如下所示:model=Sequential()model.add(LSTM(hidden_neurons,input_shape=(time_steps,feature_count),return_sequences=False))model.add(Dense(feature_count))model.add(Activati

python - Keras + tensorflow 给出错误 "no attribute ' control_flow_ops'”

我是第一次尝试运行keras。我安装了模块:pipinstallkeras--userpipinstalltensorflow--user然后尝试运行https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py.然而它给了我:AttributeError:'module'objecthasnoattribute'control_flow_ops'这些是我正在使用的版本。printtensorflow.__version__0.11.0rc0printkeras.__version__1.1.0WhatcanIdo

python - 在 Keras 中使用 Tensorflow Huber 损失

我正在尝试在keras模型中使用huber损失(编写DQN),但结果很糟糕,我认为我做错了什么。我的代码如下。model=Sequential()model.add(Dense(output_dim=64,activation='relu',input_dim=state_dim))model.add(Dense(output_dim=number_of_actions,activation='linear'))loss=tf.losses.huber_loss(delta=1.0)model.compile(loss=loss,opt='sgd')returnmodel

python - Keras:如何将 fit_generator 与不同类型的多个输出一起使用

在具有函数式API的Keras模型中,我需要调用fit_generator以使用ImageDataGenerator对增强图像数据进行训练。问题是我的模型有两个输出:我试图预测的掩码和一个二进制值。我显然只想增加输入和掩码输出,而不是二进制值。我怎样才能做到这一点? 最佳答案 下面的例子可能是不言自明的!“虚拟”模型接受1个输入(图像)并输出2个值。该模型计算每个输出的MSE。x=Convolution2D(8,5,5,subsample=(1,1))(image_input)x=Activation('relu')(x)x=Fla