小编Sta*_*ess的帖子

Keras:Binary_crossentropy具有负值

我正在使用我自己的数据集来学习本教程(第6部分:将所有内容捆绑在一起).我可以使用提供的样本数据集让教程中的示例正常工作,没问题.

我得到一个负面的二元交叉熵错误,并没有随着时代的进展而改进.我很确定二进制交叉熵应该总是正的,我应该看到损失有所改善.我已将下面的示例输出(和代码调用)截断到5个时期.其他人似乎在训练CNN时遇到类似的问题,但在我的案例中我没有看到明确的解决方案.有谁知道为什么会这样?

样本输出:

Creating TensorFlow device (/gpu:2) -> (device: 2, name: GeForce GTX TITAN Black, pci bus id: 0000:84:00.0)
10240/10240 [==============================] - 2s - loss: -5.5378 - acc: 0.5000 - val_loss: -7.9712 - val_acc: 0.5000
Epoch 2/5
10240/10240 [==============================] - 0s - loss: -7.9712 - acc: 0.5000 - val_loss: -7.9712 - val_acc: 0.5000
Epoch 3/5
10240/10240 [==============================] - 0s - loss: -7.9712 - acc: 0.5000 - val_loss: -7.9712 - val_acc: 0.5000
Epoch 4/5
10240/10240 [==============================] - 0s - …
Run Code Online (Sandbox Code Playgroud)

python keras

14
推荐指数
1
解决办法
9892
查看次数

Keras class_weight在多标签二进制分类中

无法使用class_weight来解决我的多标签问题.也就是说,每个标签都是0或1,但每个输入样本有许多标签.

代码(用于MWE目的的随机数据):

import tensorflow as tf
from keras.models import Sequential, Model
from keras.layers import Input, Concatenate, LSTM, Dense
from keras import optimizers
from keras.utils import to_categorical
from keras import backend as K
import numpy as np

# from http://www.deepideas.net/unbalanced-classes-machine-learning/
def sensitivity(y_true, y_pred):
        true_positives = tf.reduce_sum(tf.round(K.clip(y_true * y_pred, 0, 1)))
        possible_positives = tf.reduce_sum(tf.round(K.clip(y_true, 0, 1)))
        return true_positives / (possible_positives + K.epsilon())

# from http://www.deepideas.net/unbalanced-classes-machine-learning/    
def specificity(y_true, y_pred):
        true_negatives = tf.reduce_sum(K.round(K.clip((1-y_true) * (1-y_pred), 0, 1)))
        possible_negatives = tf.reduce_sum(K.round(K.clip(1-y_true, 0, 1)))
        return true_negatives …
Run Code Online (Sandbox Code Playgroud)

classification machine-learning multilabel-classification keras tensorflow

9
推荐指数
3
解决办法
3476
查看次数

如何从pickle文件一次加载一行?

我有一个大型数据集:20,000 x 40,000作为numpy数组.我已将其保存为pickle文件.

我不想将这个庞大的数据集读入内存,而是一次只读取几行(比方说100行),用作小批量.

如何从pickle文件中只读取一些随机选择(无替换)的行?

python numpy pickle

7
推荐指数
2
解决办法
6970
查看次数

如何在tikz中增加一个节点标签的字体大小

我有一张tikz图片:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes, shadows, arrows}
\begin{document}
\thispagestyle{empty}
\tikzstyle{abstract}=[circle, draw=black, fill=white]
\tikzstyle{labelnode}=[circle, draw=white, fill=white]
\tikzstyle{line} = [draw, -latex']

\begin{tikzpicture}[
    every node/.style={line width=2mm, circle split, draw, minimum size=5cm}
    ]
    \node (output) [thick, font=\fontsize{60}{60}\selectfont, thick] {$y_{(out)}$ \nodepart{lower} $y_{(in)}$};
    \node (hidden) [thick, font=\fontsize{60}{60}\selectfont, below=1cm of output] {$h_{(out)}$ \nodepart{lower} $h_{(in)}$};
    \node (input) [thick, font=\fontsize{60}{60}\selectfont, below=1cm of output, abstract, below=of hidden] {$x$};
\draw[line width=1mm, ->] (input) -- (hidden) node[font=\fontsize{60}{60}\selectfont, below=of output, labelnode, midway, right=2cm] {$W_1\, {\rm{, }} \,b_1$};
\draw[line width=1mm, ->] (hidden) -- (output) …
Run Code Online (Sandbox Code Playgroud)

tikz

7
推荐指数
1
解决办法
1万
查看次数

功能API中的Keras Multiply()层

在新的API更改下,如何在Keras中逐层实现层的乘法?在旧的API下,我会尝试这样的事情:

merge([dense_all, dense_att], output_shape=10, mode='mul')
Run Code Online (Sandbox Code Playgroud)

我试过这个(MWE):

from keras.models import Model
from keras.layers import Input, Dense, Multiply

def sample_model():
        model_in = Input(shape=(10,))
        dense_all = Dense(10,)(model_in)
        dense_att = Dense(10, activation='softmax')(model_in)
        att_mull = Multiply([dense_all, dense_att]) #merge([dense_all, dense_att], output_shape=10, mode='mul')
        model_out = Dense(10, activation="sigmoid")(att_mull)
        return 0

if __name__ == '__main__':
        sample_model()
Run Code Online (Sandbox Code Playgroud)

完整跟踪:

Using TensorFlow backend.
Traceback (most recent call last):
  File "testJan17.py", line 13, in <module>
    sample_model()
  File "testJan17.py", line 8, in sample_model
    att_mull = Multiply([dense_all, dense_att]) #merge([dense_all, dense_att], output_shape=10, mode='mul')
TypeError: __init__() takes …
Run Code Online (Sandbox Code Playgroud)

python machine-learning neural-network deep-learning keras

6
推荐指数
3
解决办法
1万
查看次数

numpy外层的用户定义函数

我有一个很长的 numpy 数组,但假设它看起来像这样:

>>> arr1 = np.array([0.001, 0.02, 0.021])
Run Code Online (Sandbox Code Playgroud)

我想一次访问数组中的两个元素并对它们执行操作。例如,我想这样做:

np.cos(arr1[0])*np.cos(arr1[1])
np.cos(arr1[0])*np.cos(arr1[2])
np.cos(arr1[1])*np.cos(arr1[2])
Run Code Online (Sandbox Code Playgroud)

我熟悉函数“outer”,我可以用它做减法:

>>> np.subtract.outer(arr1, arr1)
array([[ 0.   , -0.019, -0.02 ],
       [ 0.019,  0.   , -0.001],
       [ 0.02 ,  0.001,  0.   ]])
Run Code Online (Sandbox Code Playgroud)

如何将我自己的函数输入到 numpy 的外部?

编辑:基于评论中的一个问题,我希望函数返回如下内容:

我想要与 numpy 的外部函数返回的模式相同的模式。

array([[ np.cos(arr1[0])*np.cos(arr1[0]), np.cos(arr1[0])*np.cos(arr1[1]), np.cos(arr1[0])*np.cos(arr1[2]) ],

[ np.cos(arr1[1])*np.cos(arr1[0]), np.cos(arr1[1])*np.cos(arr1[1]), np.cos(arr1[1])*np.cos(arr1[2]) ],

[ np.cos(arr1[2])*np.cos(arr1[0]), np.cos(arr1[2])*np.cos(arr1[1]), np.cos(arr1[2])*np.cos(arr1[2]) ]])
Run Code Online (Sandbox Code Playgroud)

python numpy

5
推荐指数
1
解决办法
1021
查看次数

从R中的用户定义语料库中删除停用词

我有一套文件:

documents = c("She had toast for breakfast",
 "The coffee this morning was excellent", 
 "For lunch let's all have pancakes", 
 "Later in the day, there will be more talks", 
 "The talks on the first day were great", 
 "The second day should have good presentations too")
Run Code Online (Sandbox Code Playgroud)

在这组文件中,我想删除停用词.我已经删除了标点并转换为小写,使用:

documents = tolower(documents) #make it lower case
documents = gsub('[[:punct:]]', '', documents) #remove punctuation
Run Code Online (Sandbox Code Playgroud)

首先我转换为Corpus对象:

documents <- Corpus(VectorSource(documents))
Run Code Online (Sandbox Code Playgroud)

然后我尝试删除停用词:

documents = tm_map(documents, removeWords, stopwords('english')) #remove stopwords
Run Code Online (Sandbox Code Playgroud)

但是最后一行会导致以下错误:

调试的THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC().

这已经在这里被问到, …

r topic-modeling tm

4
推荐指数
1
解决办法
3万
查看次数

Keras:学习费率表

我正在Keras实施MLP,并调整超参数.实验的一个目标是学习率.我正在尝试使用两个计划,这两个计划都在本教程中概述.一个是使用学习速率/时期专门定义的,一个使用单独定义的步骤衰减函数.必要的代码如下.

错误是'"schedule"函数的输出应该是float'.我特意将学习率作为一个浮点数,所以我不确定我哪里出错了?

编辑:原始代码不是MWE,我道歉.要重现此错误,您可以保存下面的数据片段并运行此代码.

import numpy as np
import sys, argparse, keras, string
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.callbacks import LearningRateScheduler, EarlyStopping
from keras.optimizers import SGD
from keras.constraints import maxnorm

def load_data(data_file, test_file):
    dataset = np.loadtxt(data_file, delimiter=",")

    # split into input (X) and output (Y) variables
    X = dataset[:, 0:(dataset.shape[1]-2)]
    Y = dataset[:, dataset.shape[1]-1]
    Y = Y - 1

    testset = np.loadtxt(test_file, delimiter=",")

    X_test = testset[:, 0:(testset.shape[1]-2)]
    Y_test = testset[:, testset.shape[1]-1] …
Run Code Online (Sandbox Code Playgroud)

python machine-learning keras

4
推荐指数
1
解决办法
9899
查看次数

Keras:test_on_batch和predict_on_batch之间的区别

在Philippe Remy 关于有状态LSTM 的博客文章中,他在底部说"你可能必须通过调用predict_on_batch()或test_on_batch()来手动进行验证/测试".

查看文档,predict_on_batch执行此操作:

predict_on_batch(self, x)

Returns predictions for a single batch of samples.

Arguments

    x: Input samples, as a Numpy array.

Returns

Numpy array(s) of predictions.
Run Code Online (Sandbox Code Playgroud)

test_on_batch执行此操作:

test_on_batch(self, x, y, sample_weight=None)

Test the model on a single batch of samples.

Arguments

    x: Numpy array of test data, or list of Numpy arrays if the model has multiple inputs. If all inputs in the model are named, you can also pass a dictionary mapping input …
Run Code Online (Sandbox Code Playgroud)

python machine-learning neural-network deep-learning keras

4
推荐指数
1
解决办法
3752
查看次数

无效的ELF标头张量流

我首先尝试通过以下方式安装tensorflow:

user@WS1:~/July 2016$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl

user@WS1:~/July 2016$ pip install --upgrade $TF_BINARY_URL
Run Code Online (Sandbox Code Playgroud)

然后我试图使用从溶液中(对于Linux和tensorflow 0.9.0稍作修改的版本)iRapha这里:

user@WS1:~/July 2016$ wget https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl

user@WS1:~/July 2016$ pip install tensorflow-0.9.0-cp27-none-linux_x86_64.whl
Run Code Online (Sandbox Code Playgroud)

然后我尝试测试tensorflow是否已成功安装.以下输出显示存在"无效的ELF标头"错误.

user@WS1:~/July 2016$ python
Python 2.7.12 |Anaconda 2.5.0 (64-bit)| (default, Jul  2 2016, 17:42:40) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/export/mlrg/caugusta/anaconda2/lib/python2.7/site-packages   /tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/export/mlrg/caugusta/anaconda2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 48, in <module>
    from tensorflow.python import …
Run Code Online (Sandbox Code Playgroud)

python anaconda tensorflow

2
推荐指数
1
解决办法
5644
查看次数