当我尝试使用以下方法将图像转换为灰度时:
from skimage.io import imread
from skimage.color import rgb2gray
mountain_r = rgb2gray(imread(os.getcwd() + '/mountain.jpg'))
#Plot
import matplotlib.pyplot as plt
plt.figure(0)
plt.imshow(mountain_r)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我有一个奇怪的彩色图像而不是灰度.
手动实现该功能也给了我相同的结果.自定义功能是:
def rgb2grey(rgb):
if len(rgb.shape) is 3:
return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])
else:
print 'Current image is already in grayscale.'
return rgb
Run Code Online (Sandbox Code Playgroud)
为什么函数不能将图像转换为灰度?
例如,在我创建操作后,通过操作提供批处理数据并运行操作,tf.train.batch是否自动将另一批数据输入到会话中?
我问这个是因为tf.train.batch的属性allow_smaller_final_batch使得最终批次的加载大小小于指定的批量大小.这是否意味着即使没有循环,下一批可以自动进给?从教程代码我很困惑.当我加载一个批处理时,我实际上只有一个批量大小的形状[batch_size,height,width,num_channels],但是文档说它Creates batches of tensors in tensors.也是,当我在tf-slim演练教程中阅读教程代码时,一个名为load_batch的函数,只返回了3个张量:images, images_raw, labels.如文档中所述,"批量"数据在哪里?
谢谢您的帮助.
machine-learning computer-vision deep-learning tensorflow tf-slim
可以将检查点模型转换为冻结图(.ckpt文件到.pb文件).但是,有没有一种将pb文件再次转换为检查点文件的反向方法?
我想它需要将常量转换回变量 - 有没有办法将正确的常量识别为变量并将它们恢复为检查点模型?
目前支持将变量转换为常量:https://www.tensorflow.org/api_docs/python/tf/graph_util/convert_variables_to_constants
但不是相反.
这里提出了类似的问题:Tensorflow:将常数张量从预训练的Vgg模型转换为变量
但该解决方案依赖于使用ckpt模型来恢复权重变量.有没有办法从PB文件而不是检查点文件中恢复权重变量?这对于重量修剪可能很有用.
我能得到的最接近的例子是这个问题:https://github.com/tensorflow/tensorflow/issues/899
使用此最小可重现代码:
import tensorflow as tf
import tensorflow.python.framework.ops as ops
g = tf.Graph()
with g.as_default():
A = tf.Variable(tf.random_normal( [25,16] ))
B = tf.Variable(tf.random_normal( [16,9] ))
C = tf.matmul(A,B) # shape=[25,9]
for op in g.get_operations():
flops = ops.get_stats_for_node_def(g, op.node_def, 'flops').value
if flops is not None:
print 'Flops should be ~',2*25*16*9
print '25 x 25 x 9 would be',2*25*25*9 # ignores internal dim, repeats first
print 'TF stats gives',flops
Run Code Online (Sandbox Code Playgroud)
但是,返回的FLOPS始终为None.有没有办法具体测量FLOPS,尤其是PB文件?
我正在尝试安装Anaconda的TensorFlow(My Python是3.5.2版).
当我跑:
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl
Run Code Online (Sandbox Code Playgroud)
根据Tensorflow.org中的指南,出现了以下提示:
Exception:
Traceback (most recent call last):
File "C:\Users\Anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\Anaconda3\lib\site-packages\pip\commands\install.py", line 317, in run
prefix=options.prefix_path,
File "C:Anaconda3\lib\site-packages\pip\req\req_set.py", line 742, in install
**kwargs
File "C:\Users\Anaconda3\lib\site-packages\pip\req\req_install.py", line 831, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "C:\Users\Anaconda3\lib\site-packages\pip\req\req_install.py", line 1032, in move_wheel_files
isolated=self.isolated,
File "C:\Users\Anaconda3\lib\site-packages\pip\wheel.py", line 346, in move_wheel_files
clobber(source, lib_dir, True)
File "C:\Users\Anaconda3\lib\site-packages\pip\wheel.py", line 324, in clobber
shutil.copyfile(srcfile, destfile)
File "C:\Users\Anaconda3\lib\shutil.py", line 115, in copyfile
with …Run Code Online (Sandbox Code Playgroud) 非常简单地说,对于相同的训练数据帧df,当我使用X = df.iloc [:,:-1] .values时,它将选择直到数据帧的倒数第二列而不是最后一列(这是我想要的但是这是一个我以前从未见过的奇怪行为,而且我知道这是第二列的第二个值,而该行的最后一列的值是不同的.
但是,使用y = df.iloc [:, - 1] .values给出了最后一列的值的行向量,这正是我想要的.为什么X的负1给我第二列的第二个值呢?

我已按照https://datanoord.com/2016/02/01/setup-a-deep-learning-environment-on-windows-theano-keras-with-gpu-enabled/的所有说明进行操作, 但似乎无法让它工作.
我已将C:\ Program Files(x86)\ Microsoft Visual Studio 12.0\VC\bin添加到我的PATH变量中
每次我从Theano网站运行代码来测试是否使用了CPU或GPU时,它会给我一个致命的错误:"nvcc致命:在PATH中找不到编译器'cl.exe'"
这是我用来测试的代码:
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, …Run Code Online (Sandbox Code Playgroud) 是否有一种直接的方法来查找由张量流初始化的inception-resnet-v2模型消耗的GPU内存?这包括推理和所需的后备存储器.
我有一个尺寸为5000 x 3027(CIFAR-10数据集)的矩阵形式的训练数据集.在numpy中使用array_split,我将它分成5个不同的部分,我想只选择其中一个部分作为交叉验证折叠.然而,当我使用像XTrain [[Indexes]]之类的东西时,我的问题出现了,其中索引是像[0,1,2,3]这样的数组,因为这样做会给我一个尺寸为4 x 1000 x 3027的3D张量,而不是矩阵.如何将"4 x 1000"折叠成4000行,以获得4000 x 3027的矩阵?
for fold in range(len(X_train_folds)):
indexes = np.delete(np.arange(len(X_train_folds)), fold)
XTrain = X_train_folds[indexes]
X_cv = X_train_folds[fold]
yTrain = y_train_folds[indexes]
y_cv = y_train_folds[fold]
classifier.train(XTrain, yTrain)
dists = classifier.compute_distances_no_loops(X_cv)
y_test_pred = classifier.predict_labels(dists, k)
num_correct = np.sum(y_test_pred == y_test)
accuracy = float(num_correct/num_test)
k_to_accuracy[k] = accuracy
Run Code Online (Sandbox Code Playgroud) 意思是说如果我有下面的图表:
images, labels = load_batch(...)
with slim.arg_scope(inception_resnet_v2_arg_scope()):
logits, end_points = inception_resnet_v2(images, num_classes = dataset.num_classes, is_training = True)
predictions = tf.argmax(end_points['Predictions'], 1)
accuracy, accuracy_update = tf.contrib.metrics.streaming_accuracy(predictions, labels)
....
train_op = slim.learning.create_train_op(...)
Run Code Online (Sandbox Code Playgroud)
managed_session在图形上下文中的主管中sess,我每隔一段时间运行以下命令:
print sess.run(logits)
print sess.run(end_points['Predictions'])
print sess.run(predictions)
print sess.run(labels)
Run Code Online (Sandbox Code Playgroud)
考虑到批处理张量实际上必须在load_batch到达logits、predictions或之前从头开始,它们实际上是否会为每次 sess 运行调用不同的批处理labels?因为现在当我运行每个会话时,我得到一个非常令人困惑的结果,即使预测也不匹配tf.argmax(end_points['Predictions'], 1),尽管模型的准确性很高,但我没有得到任何与标签远程匹配的预测来给出这种类型的高精度。因此我怀疑每个结果sess.run可能来自不同批次的数据。
这引出了我的下一个问题:当 load_batch 中的批次一直到 train_op(实际上是在 train_op 中sess.run运行)时,有没有办法检查图表不同部分的结果?换句话说,有没有一种方法可以做我想做的事而不需要另一个sess.run?
另外,如果我以这种方式使用 sess.run 检查结果,是否会影响我的训练,因为某些批次的数据将被跳过而不会到达 train_op?
python machine-learning computer-vision deep-learning tensorflow