小编Par*_*roi的帖子

ValueError:尝试共享变量rnn/multi_rnn_cell/cell_0/basic_lstm_cell/kernel

这就是代码:

X = tf.placeholder(tf.float32, [batch_size, seq_len_1, 1], name='X')
labels = tf.placeholder(tf.float32, [None, alpha_size], name='labels')

rnn_cell = tf.contrib.rnn.BasicLSTMCell(512)
m_rnn_cell = tf.contrib.rnn.MultiRNNCell([rnn_cell] * 3, state_is_tuple=True)
pre_prediction, state = tf.nn.dynamic_rnn(m_rnn_cell, X, dtype=tf.float32)
Run Code Online (Sandbox Code Playgroud)

这是完整的错误:

ValueError:尝试共享变量rnn/multi_rnn_cell/cell_0/basic_lstm_cell/kernel,但指定形状(1024,2048)并找到形状(513,2048).

我正在使用GPU版本的tensorflow.

deep-learning lstm tensorflow

19
推荐指数
3
解决办法
9227
查看次数

TypeError:concat()为参数'axis'获取了多个值

这是我的卷积神经网络:

def convolutional_neural_network(frame):
    wts = {'conv1': tf.random_normal([5, 5, 3, 32]),
            'conv2': tf.random_normal([5, 5, 32, 64]),
            'fc': tf.random_normal([158*117*64 + 4, 128]),
            'out': tf.random_normal([128, n_classes])
            }
    biases = {'fc': tf.random_normal([128]),
                'out': tf.random_normal([n_classes])
            }

    conv1 = conv2d(frame, wts['conv1'])
    # print(conv1)
    conv1 = maxpool2d(conv1)
    # print(conv1)
    conv2 = conv2d(conv1, wts['conv2'])
    conv2 = maxpool2d(conv2)
    # print(conv2)
    conv2 = tf.reshape(conv2, shape=[-1,158*117*64])
    print(conv2)
    print(controls_at_each_frame)
    conv2 = tf.concat(conv2, controls_at_each_frame, axis=1)
    fc = tf.add(tf.matmul(conv2, wts['fc']), biases['fc'])

    output = tf.nn.relu(tf.add(tf.matmul(fc, wts['out']), biases['out']))

    return output
Run Code Online (Sandbox Code Playgroud)

哪里

frame = tf.placeholder('float', [None, 640-10, …
Run Code Online (Sandbox Code Playgroud)

python neural-network conv-neural-network tensorflow

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

Firebase云功能返回304错误,然后重新启动

我已经坚持了几个月。我从函数中删除了一些次要细节,但没有什么大不了的。我有这个https云函数,该函数结束会话,然后使用endTimestartTime计算bill返回到客户端的值。

startTime 从实时Firebase数据库(会话启动程序函数放在那里)中检索。

我的代码段:

exports.endSession = functions.https.onRequest(async (req, res) => {
    console.log("endSession() called.")
    if(req.method == 'GET'){
        bid = req.query.bid
        session_cost = req.query.sessioncost
    }else{
        bid = req.body.bid
        session_cost = req.body.sessioncost
    }

start_time_ref = admin.database().ref("/online_sessions/").child(bid).child("start_time")
start_time_snapshot = await start_time_ref.once('value')

console.log("start_time_snapshot: "+start_time_snapshot.val())

start_time_snapshot = moment(start_time_snapshot.val(), 'dddd MMMM Do YYYY HH:mm:ss Z');
endDateTime = getDateTime()

console.log("startTime: " + start_time_snapshot.toString())
console.log("endTime: " + endDateTime.toString())
hour_difference = getHourDifference(start_time_snapshot, endDateTime)

bill = ride_cost * Math.ceil(hour_difference)
console.log("bill: "+bill)

var s_phone
sSessionlinks_ref = …
Run Code Online (Sandbox Code Playgroud)

javascript node.js firebase firebase-realtime-database google-cloud-functions

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

Firebase - TypeError: admin.auth(...).createUserWithEmailAndPassword 不是函数

我正在尝试使用云函数在 firebase 数据库中创建一个用户。这是我的代码:

exports.AddUser = functions.https.onRequest(function(req, res){

    if(req.method == 'GET'){
        email = req.query.email;
        password = req.query.password;
        name = req.query.name;

        admin.auth().createUserWithEmailAndPassword(email, password).then(function(user){
            user.sendEmailVerification().then(function(){
                res.send("verification email sent.");
            }).catch(function(){
                res.end(user)
            })
        })
        .catch(function(error) {
            // Handle Errors here.
            var errorCode = error.code;
            var errorMessage = error.message;
            console.log(errorMessage);
            res.send(errorMessage);
        });

    }else{
        email = req.body.email;
        password = req.body.password;
        name = req.body.name;

        admin.auth().createUserWithEmailAndPassword(email, password).then(function(user){
            user.sendEmailVerification().then(function(){
                res.send("verification email sent.");
            }).catch(function(error){
                res.end(user)
            });
        })
        .catch(function(error) {
            // Handle Errors here.
            var errorCode = error.code;
            var errorMessage = error.message; …
Run Code Online (Sandbox Code Playgroud)

node.js firebase firebase-authentication google-cloud-functions firebase-admin

5
推荐指数
2
解决办法
3079
查看次数

如何在服务器端运行firebase?

我想使用 firebase 作为我的服务器的数据库服务,android 应用程序将向其发送请求。我希望服务器检索数据而不是 Android 应用程序,因为我想在将数据发送回客户端(应用程序)之前进行一些处理。

我的节点代码(index.js):

const express = require('express')
const app = express()

var port = process.env.PORT || 10000

firebase = require('./firebase') // I added this cuz I can't use <script> tag here

// Initialize Firebase
var config = {
    apiKey: "AIzaSynotgonnatell2Q-kwk85XrCyNnc",
    authDomain: "hnotgonnatell.firebaseapp.com",
    databaseURL: "https://hnotgonnatell.firebaseio.com",
    projectId: "notgonnatell",
    storageBucket: "",
    messagingSenderId: "699935506077"
};

firebase.initializeApp(config);

var database = firebase.database()

ref = database.ref("some_table")

data = {
    name : "my name",
    number : "2938019283"
}

app.get('/', function(req, res){
    ref.push(data)
    res.send("hello")
}) …
Run Code Online (Sandbox Code Playgroud)

javascript node.js firebase server firebase-realtime-database

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

为什么不训练这样的GAN呢?

我是生成网络的新手,我决定在看到代码之前先自己尝试一下.这些是我用来训练我的GAN的步骤.

[lib:tensorflow]

1)在数据集上训练鉴别器.(我使用了2个功能的数据集,标签为'mediatating'或'not meditating',数据集:https://drive.google.com/open?id = 0B5DaSp-aTU-KSmZtVmFoc0hRa3c )

2)一旦鉴别器被训练,保存它.

3)使用另一个前馈网络(或任何其他取决于您的数据集)创建另一个文件.该前馈网络是发电机.

4)一旦构建了发生器,恢复鉴别器并为发生器定义一个损失函数,使它学会欺骗鉴别器.(这在tensorflow中不起作用,因为sess.run()不返回tf张量,G和D之间的路径中断,但从头开始时应该有效)

d_output = sess.run(graph.get_tensor_by_name('ol:0'), feed_dict={graph.get_tensor_by_name('features_placeholder:0'): g_output})
print(d_output)

optimize_for = tf.constant([[0.0]*10]) #not meditating

g_loss = -tf.reduce_mean((d_output - optimize_for)**2)

train = tf.train.GradientDescentOptimizer(learning_rate).minimize(g_loss)
Run Code Online (Sandbox Code Playgroud)

我们为什么不训练这样的发电机?这似乎更简单.确实,我无法设法在张量流上运行它,但如果我从头开始这应该是可能的.

完整代码:

鉴别:

import pandas as pd
import tensorflow as tf
from sklearn.utils import shuffle

data = pd.read_csv("E:/workspace_py/datasets/simdata/linear_data_train.csv")

learning_rate = 0.001
batch_size = 1
n_epochs = 1000
n_examples = 999 # This is highly unsatisfying >:3
n_iteration = int(n_examples/batch_size)


features = tf.placeholder('float', [None, 2], name='features_placeholder')
labels = …
Run Code Online (Sandbox Code Playgroud)

python neural-network deep-learning tensorflow

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

权重和偏差不在张量流中更新

我已经制作了这个神经网络,以确定一个房子是好买还是坏买.由于某些原因,代码不会更新权重和偏差.我的损失保持不变.这是我的代码:

我已经制作了这个神经网络,以确定一个房子是好买还是坏买.由于某些原因,代码不会更新权重和偏差.我的损失保持不变.这是我的代码:

import pandas as pd
import tensorflow as tf

data = pd.read_csv("E:/workspace_py/datasets/good_bad_buy.csv")

features = data.drop(['index', 'good buy'], axis = 1)
lbls = data.drop(['index', 'area', 'bathrooms', 'price', 'sq_price'], axis = 1)

features = features[0:20]
lbls = lbls[0:20]

print(features)
print(lbls)
n_examples = len(lbls)

# Model

# Hyper parameters

epochs = 100
learning_rate = 0.1
batch_size = 1

input_data = tf.placeholder('float', [None, 4])
labels = tf.placeholder('float', [None, 1])

weights = {
            'hl1': tf.Variable(tf.random_normal([4, 10])),
            'hl2': tf.Variable(tf.random_normal([10, 10])),
            'hl3': tf.Variable(tf.random_normal([10, 4])),
            'ol': tf.Variable(tf.random_normal([4, …
Run Code Online (Sandbox Code Playgroud)

python machine-learning neural-network tensorflow tensorflow-gpu

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

Keras:损失不断增加

代码:

import keras
import numpy as np

x = []
y = []

for i in range(1000):
    x.append((i/10.0))
    y.append(2.71828 ** (i/10.0))

x = np.asarray(x)
y = np.asarray(y)
x = x.T
y = y.T

model = keras.models.Sequential()
model.add(keras.layers.Dense(1, input_dim=1, activation='relu'))
model.add(keras.layers.Dense(100, activation='relu'))
model.add(keras.layers.Dense(1))

model.compile(loss='mean_squared_error', optimizer=keras.optimizers.SGD(lr=0.001))
model.fit(x, y, batch_size=1, shuffle=False)

tx = [0.0, 1.0, 10.0]
tx = np.asarray(tx)
tx = tx.T

print(model.predict(tx))
Run Code Online (Sandbox Code Playgroud)

这是一个非常简单的神经网络,旨在映射 e^x。这是我第一次使用 keras,当我运行它时,损失不断增加到无穷大。相反,它应该减少。

python neural-network deep-learning keras tensorflow

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