小编Eng*_*ero的帖子

tensorflow:简单LSTM网络的共享变量错误

我正在尝试构建一个最简单的LSTM网络.只是希望它预测序列中的下一个值np_input_data.

import tensorflow as tf
from tensorflow.python.ops import rnn_cell
import numpy as np

num_steps = 3
num_units = 1
np_input_data = [np.array([[1.],[2.]]), np.array([[2.],[3.]]), np.array([[3.],[4.]])]

batch_size = 2

graph = tf.Graph()

with graph.as_default():
    tf_inputs = [tf.placeholder(tf.float32, [batch_size, 1]) for _ in range(num_steps)]

    lstm = rnn_cell.BasicLSTMCell(num_units)
    initial_state = state = tf.zeros([batch_size, lstm.state_size])
    loss = 0

    for i in range(num_steps-1):
        output, state = lstm(tf_inputs[i], state)
        loss += tf.reduce_mean(tf.square(output - tf_inputs[i+1]))

with tf.Session(graph=graph) as session:
    tf.initialize_all_variables().run()

    feed_dict={tf_inputs[i]: np_input_data[i] for i in range(len(np_input_data))} …
Run Code Online (Sandbox Code Playgroud)

python neural-network lstm tensorflow

3
推荐指数
2
解决办法
6167
查看次数

连接2 Julia Arrays而不修改它们

我想连接2个数组.

julia> l1=["a","b"]
2-element Array{ASCIIString,1}:
 "a"
 "b"

julia> l2=["c","d"]
2-element Array{ASCIIString,1}:
 "c"
 "d"
Run Code Online (Sandbox Code Playgroud)

append!可以做到这一点,但这个功能正在修改l1!`)

julia> append!(l1, l2)
4-element Array{ASCIIString,1}:
 "a"
 "b"
 "c"
 "d"

julia> l1
4-element Array{ASCIIString,1}:
 "a"
 "b"
 "c"
 "d"
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个!功能(没有感叹号).

但这样的功能似乎并不存在.

任何的想法 ?

arrays list julia

3
推荐指数
2
解决办法
998
查看次数

RNN(keras)的欧几里得距离损失函数

我想将欧几里得距离设置为LSTM或RNN的损失函数。

该函数应具有什么输出:float,(batch_size)或(batch_size,时间步长)?

模型输入X_train是(n_samples,时间步长,data_dim)。Y_train具有相同的尺寸。

示例代码:

def euc_dist_keras(x, y):
    return K.sqrt(K.sum(K.square(x - y), axis=-1, keepdims=True))


model = Sequential()
model.add(SimpleRNN(n_units, activation='relu', input_shape=(timesteps, data_dim), return_sequences=True))
model.add(Dense(n_output, activation='linear'))

model.compile(loss=euc_dist_keras, optimizer='adagrad')

model.fit(y_train, y_train, batch_size=512, epochs=10)
Run Code Online (Sandbox Code Playgroud)

因此,我应该在时间步长维度和/或batch_size中平均损失吗?

loss keras rnn

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

tensorflow eager模块出错

我的操作系统是Ubuntu 16.04

Python版本是3.5

Tensorflow版本是14.0

当我尝试TF Eager模块的简单代码时

import tensorflow as tf
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()
x = [[2.]]
m = tf.matmul(x, x)
Run Code Online (Sandbox Code Playgroud)

我有

AttributeError:模块'tensorflow.contrib.eager'没有属性'enable_eager_execution'

那有什么不对?

tensorflow

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

在Pandas中将Unix纪元时间转换为日期时间

我一直在寻找很长时间来找到解决我的问题的方法。

我使用以下代码从想要的列中获取数据

import pandas as pd
df = pd.read_excel("Live_data_test.xlsx","Sheet1")

number_of_entries = len(df.loc[:, 'Time'])
number_of_entries_last_3 = number_of_entries - 3
unix_x1 = df.loc[number_of_entries_last_:number_of_entries, 'Time']
print(unix_x1)
Run Code Online (Sandbox Code Playgroud)

我得到了输出

10    1.513753e+09
11    1.513753e+09
12    1.513753e+09
Name: Time, dtype: float64
Run Code Online (Sandbox Code Playgroud)

我想将此时间转换为可读时间,以便将其输入到matplotlib图的x轴中。

real_x1 = datetime.datetime.strptime(str(unix_x1), '%Y-%m-%d %H:%M:%S')
Run Code Online (Sandbox Code Playgroud)

我得到错误

ValueError: time data '10    1.513753e+09\n11    1.513753e+09\n12    1.513753e+09\nName: Time, dtype: float64' does not match format '%Y-%m-%d %H:%M:%S'
Run Code Online (Sandbox Code Playgroud)

我如何获得这个unix时间来输出为用户可读的格式?

我对代码有点陌生,所以如果您回答,是否可以解释原因?

python excel matplotlib pandas

3
推荐指数
2
解决办法
2407
查看次数

Tensorflow Python 3.7

适用于Python 3.7的Tensorflow版本

有关python 3.7的tensorflow更新的任何新闻。当我尝试在我的venv中安装tensorflow时:

pip install tensorflow
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

找不到满足需求tensorflow的版本(来自版本
:)找不到与tensorflow匹配的分布

python virtualenv python-venv tensorflow

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

并行执行类方法

我需要并行执行同一个类的许多实例的方法.为此,我正在尝试使用模块中Process.start()Process.join()命令multiprocessing.

例如,对于一个类:

class test:
     def __init__(self):
     ...
     ...
     def method(self):
     ...
     ...
Run Code Online (Sandbox Code Playgroud)

其中method修改了一些类变量.如果我创建了两个类的实例:

t1=test()
t2=test()
Run Code Online (Sandbox Code Playgroud)

并执行:

from multiprocessing import Process
pr1=Process(target=t1.method, args=(,))
pr2=Process(target=t2.method, args=(,))
pr1.start()
pr2.start()
pr1.join()
pr2.join()
Run Code Online (Sandbox Code Playgroud)

类的实例的变量没有更新(整个代码太长了,不能粘贴在这里,但这是个主意).

有没有办法实现这个目标?谢谢

python multiprocessing

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

在matlab中,如何在不使用循环的情况下以矩阵形式生成1:n?例如,当n = 6时,我想要[1 2; 3 4; 5 6]而不是[1 2 3 4 5 6]

在MATLAB中,如何在不使用循环的情况下以2x(n/2)矩阵形式生成数字1:n?例如n=6,我想要[1 2;3 4;5 6]而不是[1 2 3 4 5 6].

matlab

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

“致命错误 C1083:无法打开包含文件”,但我已将目录添加到项目中

我认为这是一个奇怪的问题。我会尽力提供尽可能多的细节。我尝试使用以下方法在 Visual Studio 2012 测试项目中导入自定义类的标头:

#include "detector.h"
Run Code Online (Sandbox Code Playgroud)

我收到错误

致命错误 C1083:无法打开包含文件:“ detector.h”:没有这样的文件或目录

我已经包含了头文件所在文件夹的完整路径Project -> Properties -> C/C++ -> General -> Additional Include Directories

头文件相当长,但基本上只包含类的声明。该detector.cpp文件包含类的定义。我的文件系统上的目录结构如下所示:

project_directory/
  - test/
    - [my_test_project]
  - detector_directory/
    - detector.h
    - detector.cpp
  - other_component_directory/
    - other_component.h
    - other_component.cpp
  ...
Run Code Online (Sandbox Code Playgroud)

能够#include other_component.h该类编写和执行测试。我实际上能够包含其他三个类并为所有三个类编写和执行测试,但是四个类(包括detector)给了我同样的错误。

整个内容project_directory/是从 SVN 存储库中签出的,到目前为止只有我对此做出了贡献。我提到,以防链接或为存储库创建的内容可能出现一些奇怪的情况。我认为这个问题可能是在将存储库恢复到以前的更新后出现的,但不确定我是否只是在那时才注意到它。

感谢您的帮助!

c++ svn visual-studio visual-studio-2012

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

在tensorflow中检索未命名的变量

我已经训练了一个模型并将其保存在检查点中,但只是意识到我忘记在恢复模型时命名一个我想要检查的变量.

我知道如何从tensorflow(g = tf.get_default_graph()然后g.get_tensor_by_name([name]))检索命名变量.在这种情况下,我知道它的范围,但它是未命名的.我试过看了tf.GraphKeys.GLOBAL_VARIABLES,但由于某种原因它没有出现在那里.

以下是它在模型中的定义:

with tf.name_scope("contrastive_loss") as scope:
    l2_dist = tf.cast(tf.sqrt(1e-4 + tf.reduce_sum(tf.subtract(pred_left, pred_right), 1)), tf.float32) # the variable I want

    # I use it here when calculating another named tensor, if that helps.
    con_loss = contrastive_loss(l2_dist) 
    loss = tf.reduce_sum(con_loss, name="loss")
Run Code Online (Sandbox Code Playgroud)

有没有找到没有名字的变量的方法?

tensorflow

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