草庐IT

Scikit-Learn-Keras

全部标签

python - Keras:在 theano 和 tensorflow 之间转换预训练的权重

我想使用thispretrainedmodel.它在theano布局中,我的代码取决于tensorflow图像维度排序。convertingweightsbetweentheformats上有指南.但这似乎坏了。在将theano转换为tensorflow的部分中,第一条指令是将权重加载到tensorflow模型中。KerasbackendshouldbeTensorFlowinthiscase.First,loadtheTheano-trainedweightsintoyourTensorFlowmodel:model.load_weights('my_weights_theano.h

python - 注意层抛出 TypeError : Permute layer does not support masking in Keras

我一直在关注这个post为了在我的LSTM模型上实现注意力层。注意力层的代码:INPUT_DIM=2TIME_STEPS=20SINGLE_ATTENTION_VECTOR=FalseAPPLY_ATTENTION_BEFORE_LSTM=Falsedefattention_3d_block(inputs):input_dim=int(inputs.shape[2])a=Permute((2,1))(inputs)a=Reshape((input_dim,TIME_STEPS))(a)a=Dense(TIME_STEPS,activation='softmax')(a)ifSINGLE

python - Scikit 学习 SVC 预测概率无法按预期工作

我使用SVM分类器构建了情绪分析器。我用probability=True训练模型,它可以给我概率。但是当我腌制我的模型并稍后再次加载它时,概率不再起作用。模型:fromsklearn.svmimportSVC,LinearSVCpipeline_svm=Pipeline([('bow',CountVectorizer()),('tfidf',TfidfTransformer()),('classifier',SVC(probability=True)),])#pipelineparameterstoautomaticallyexploreandtuneparam_svm=[{'clas

python - Keras 与 TensorFlow : Use memory as it's needed [ResourceExhaustedError]

所以我试图用多个数据集来污染我的CNN并且当我添加足够的数据时(例如当我将多个集合作为一个集合添加或当我尝试添加具有超过一百万个样本的集合时)它会接缝抛出一个ResourceExhaustedError。至于说明here,我尝试添加fromkeras.backend.tensorflow_backendimportset_sessionimporttensorflowastfconfig=tf.ConfigProto()config.gpu_options.per_process_gpu_memory_fraction=0.3set_session(tf.Session(config=

python - 指定用于 Keras Tensorflow 模型推理的 CPU

好的。我知道我们可以使用以下方法限制Keras(TF后端)模型使用的核心数:K.set_session(K.tf.Session(config=K.tf.ConfigProto(intra_op_parallelism_threads=2,inter_op_parallelism_threads=2,device_count={'CPU':2})))我们可以像这样指定单个张量操作:withtf.device('/cpu:0'):a=tf.constant([1.0,2.0,3.0,4.0,5.0,6.0],shape=[2,3],name='a')但是如果我们想指定一个由Keras模型

python - Tensorflow 2.0 Keras 的训练速度比 2.0 Estimator 慢 4 倍

我们最近为TF2.0切换到Keras,但是当我们将它与2.0上的DNNClassifierEstimator进行比较时,我们发现Keras的速度慢了大约4倍。但我一辈子都弄不明白为什么会这样。两者的其余代码是相同的,使用返回相同tf.data.Dataset的input_fn(),并使用相同的feature_columns。几天来一直在努力解决这个问题。任何帮助将不胜感激。谢谢估算器代码:estimator=tf.estimator.DNNClassifier(feature_columns=feature_columns,hidden_units=[64,64],activation

python - scikit-learn 管道中具有递归特征消除的网格搜索返回错误

我正在尝试使用scikit-learn在管道中链接网格搜索和递归特征消除。带有“裸”分类器的GridSearchCV和RFE工作正常:fromsklearn.datasetsimportmake_friedman1fromsklearnimportfeature_selectionfromsklearn.grid_searchimportGridSearchCVfromsklearn.svmimportSVRX,y=make_friedman1(n_samples=50,n_features=10,random_state=0)est=SVR(kernel="linear")selec

python - 无法更改现有 Keras 模型中的激活

我有一个带有relu激活的普通VGG16模型,即defVGG_16(weights_path=None):model=Sequential()model.add(ZeroPadding2D((1,1),input_shape=(3,224,224)))model.add(Convolution2D(64,3,3,activation='relu'))model.add(ZeroPadding2D((1,1)))model.add(Convolution2D(64,3,3,activation='relu'))model.add(MaxPooling2D((2,2),strides=(2

python - 在 scikit-learn SVM 中缩放数据

虽然libsvm提供了用于缩放数据的工具,但使用Scikit-Learn(对于SVC分类器应该基于libSVM)我找不到缩放数据的方法。基本上我想使用4个特征,其中3个从0到1,最后一个是一个“大”高度可变的数字。如果我在libSVM中包含第四个功能(使用自动缩放我的数据的easy.py脚本),我会得到一些非常好的结果(96%的准确率)。如果我在Scikit-Learn中包含第四个变量,准确度会下降到~78%-但如果我排除它,我得到的结果与在排除该特征时在libSVM中得到的结果相同。因此,我很确定这是缺少缩放的问题。如何以编程方式(即不调用svm-scale)复制SVM的缩放过程?

python - 如何更改 Keras 中 softmax 输出的温度

我目前正在尝试重现以下文章的结果。http://karpathy.github.io/2015/05/21/rnn-effectiveness/我在theano后端使用Keras。在文章中,他谈到了控制最终softmax层的温度以提供不同的输出。Temperature.WecanalsoplaywiththetemperatureoftheSoftmaxduringsampling.Decreasingthetemperaturefrom1tosomelowernumber(e.g.0.5)makestheRNNmoreconfident,butalsomoreconservative