当我从tensorflow官方网站上关注linux的安装时,一切都很好,直到最后一步:训练你的第一个TensorFlow神经网络模型.
当我执行命令时python tensorflow/models/image/mnist/convolutional.py,会出现一个ImportError提示.
Traceback (most recent call last):
File "tensorflow/models/image/mnist/convolutional.py", line 13, in <module>
import tensorflow.python.platform
File "/home/guo/haplox/Github/tensorflow/tensorflow/__init__.py", line 4, in <module>
from tensorflow.python import *
File "/home/guo/haplox/Github/tensorflow/tensorflow/python/__init__.py", line 13, in <module>
from tensorflow.core.framework.graph_pb2 import *
ImportError: No module named core.framework.graph_pb2
Run Code Online (Sandbox Code Playgroud)
我的操作系统是14.04.1-Ubuntu.
我正在尝试在两个图像之间使用 SSD 作为我网络的损失函数。
# h_fc2 is my output layer, y_ is my label image.
ssd = tf.reduce_sum(tf.square(y_ - h_fc2))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(ssd)
Run Code Online (Sandbox Code Playgroud)
问题是,然后权重发散,我得到错误
ReluGrad input is not finite. : Tensor had Inf values
Run Code Online (Sandbox Code Playgroud)
为什么?我确实尝试了其他一些东西,例如通过图像大小标准化 ssd(不起作用)或将输出值裁剪为 1(不再崩溃,但我仍然需要对此进行评估):
ssd_min_1 = tf.reduce_sum(tf.square(y_ - tf.minimum(h_fc2, 1)))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(ssd_min_1)
Run Code Online (Sandbox Code Playgroud)
我的观察是否符合预期?
编辑:@mdaoust 建议被证明是正确的。重点是按批量大小进行标准化。这可以通过使用此代码独立于批量大小完成
squared_diff_image = tf.square(label_image - output_img)
# Sum over all dimensions except the first (the batch-dimension).
ssd_images = tf.reduce_sum(squared_diff_image, [1, 2, 3])
# Take mean ssd over batch.
error_images = tf.reduce_mean(ssd_images)
Run Code Online (Sandbox Code Playgroud)
有了这个变化,只需要稍微降低学习率(到 0.0001)。
我有一个卷积神经网络,我修改了它的架构.我没有时间重新训练并执行交叉验证(对最佳参数进行网格搜索).我想直观地调整学习率.
如果符合以下条件,我是否应该提高或降低我的RMS(基于SGD)优化器的学习率:
machine-learning neural-network deep-learning conv-neural-network
我想实现一个Siamese卷积神经网络,其中两个图像在卷积层中共享权重,然后在通过完全连接的层之前连接.我试过一个实现,但它似乎是一个"黑客"解决方案.特别是,我已经将张量上的操作定义为简单的Python函数,我不确定这是否允许.
这是我尝试过的代码:
images = tf.placeholder(tf.float32, shape=[None, 64 * 64])
# Convolutional layers
# ...
# ...
# Results in pool3_flat, which is the flattened output of the third convolutional layer
pool3_flat = tf.reshape(pool3, [-1, 8 * 8 * 128])
# Now, merge the image pairs, where each pair is composed of adjacent images in the batch, with a stride of 2
def merge_pairs():
# Create a tensor to store the merged image pairs
# The batch size is 128, therefore …Run Code Online (Sandbox Code Playgroud) 如果它是单行,我可以得到如下的迭代器
import pandas as pd
import numpy as np
a = np.zeros((100,40))
X = pd.DataFrame(a)
for index, row in X.iterrows():
print index
print row
Run Code Online (Sandbox Code Playgroud)
现在,我希望每个迭代器将返回一个子集X[0:9, :],X[5:14, :],X[10:19, :]等我怎样滚动做到这一点(pandas.DataFrame.rolling)?
在训练模型后,我尝试使用scikit获取混淆矩阵,但是由于使用flow_from_directory,我无法访问数据和标签,或者我不知道这样做的方法。由于scikit混淆矩阵方法的用法如下:
confusion_matrix(y_true, y_pred)
Run Code Online (Sandbox Code Playgroud)
并且flow_from_directory不返回真实标签。有没有办法flow_from_directory直接或其他任何方式获取它们?
我正在尝试用C++编写代码(使用模板)来添加2个矩阵.
我在.h文件中有以下代码.
#ifndef __MATRIX_H__
#define __MATRIX_H__
//***************************
// matrix
//***************************
template <class T, int rows, int cols> class matrix {
public:
T mat[rows][cols];
matrix();
matrix(T _mat[rows][cols]);
matrix operator+(const matrix& b);
};
template <class T, int rows, int cols> matrix <T,rows,cols> :: matrix (T _mat[rows][cols]){
for (int i=0; i<rows; i++){
for (int j=0; j<cols; j++){
mat[i][j] = _mat[i][j];
}
}
}
template <class T, int rows, int cols> matrix <T,rows,cols> :: matrix (){
for (int i=0; i<rows; i++){
for (int j=0; …Run Code Online (Sandbox Code Playgroud) 我有一个数据集,X即m x 2三个存储在矩阵C = [c1'; c2'; c3']中的向量3 x 2.我试图对我的代码进行矢量化,为每个数据点找到X哪个矢量C最接近(平方距离).我想减去每个向量(行)C从每个向量(行)X,导致m x 6或3m x 2的的元素之间的差异矩阵X和的元素C.我目前的实现一次只进行一行X:
for i = 1:size(X, 1)
diffs = bsxfun(@minus, X(i,:), C); % gives a 3 x 2 matrix result
[~, idx(i)] = min(sumsq(diffs), 2); % returns the index of the closest vector
% in C to the ith vector in X
end …Run Code Online (Sandbox Code Playgroud)
我正在尝试构建一个最简单的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) 我想连接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)
我正在寻找一个!功能(没有感叹号).
但这样的功能似乎并不存在.
任何的想法 ?