我的图像是478 x 717 x 3 = 1028178像素,等级为1.我通过调用tf.shape和tf.rank验证了它.
当我调用image.set_shape([478,717,3])时,它会抛出以下错误.
"Shapes %s and %s must have the same rank" % (self, other))
ValueError: Shapes (?,) and (478, 717, 3) must have the same rank
Run Code Online (Sandbox Code Playgroud)
我通过首次测试再次测试到1028178,但错误仍然存在.
ValueError: Shapes (1028178,) and (478, 717, 3) must have the same rank
Run Code Online (Sandbox Code Playgroud)
嗯,这确实有意义,因为一个是等级1而另一个是等级3.但是,为什么有必要抛出一个错误,因为像素的总数仍然匹配.
我当然可以使用tf.reshape并且它有效,但我认为这不是最佳的.
正如TensorFlow常见问题解答中所述
x.set_shape()和x = tf.reshape(x)之间有什么区别?
tf.Tensor.set_shape()方法更新Tensor对象的静态形状,并且通常用于在无法直接推断时提供其他形状信息.它不会改变张量的动态形状.
tf.reshape()操作创建一个具有不同动态形状的新张量.
创建新的张量涉及内存分配,并且当涉及更多培训示例时可能会更昂贵.这是设计,还是我在这里遗漏了什么?
我们在许多TensorFlow教程中经常看到这一点:
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True,
log_device_placement=True))
Run Code Online (Sandbox Code Playgroud)
是什么allow_soft_placement和log_device_placement意味着什么?
我是Bazel的新手.我不确定这件事是如何运作的.在TF网站上,有关于"创建pip包并安装"的部分.
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
# To build with GPU support:
$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
# The name of the .whl file will depend on your platform.
$ pip install /tmp/tensorflow_pkg/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
Run Code Online (Sandbox Code Playgroud)
情况如下:
这是正确更新master更改的正确方法吗?bazel构建步骤需要很长时间.
TensorBoard是一个很棒的工具,但它可以更强大吗?下图显示了TensorBoard中的可视化.
它由以下代码调用:
tf.image_summary('images', images, max_images=100)
Run Code Online (Sandbox Code Playgroud)
正如API建议的那样,最后一位是"图像编号",在这种情况下从0到99,因为我指定了max_images = 100.我想问一下,如果我可以将这个图像的标签附加到文本中?这将是一个很棒的功能,因为它允许用户在训练期间实时查看图像及其各自的标签.在某些图像被完全贴错标签的情况下,可以实现修复.换句话说,我希望下图中的相应文字是:
images/image/9/5
images/image/39/6
images/image/31/0
images/image/30/2
where last digit is the label.
Run Code Online (Sandbox Code Playgroud)
谢谢!
主要思想是将TFRecords转换为numpy数组.假设TFRecord存储图像.特别:
Run Code Online (Sandbox Code Playgroud)1.jpg 2 2.jpg 4 3.jpg 5
我目前使用以下代码:
import tensorflow as tf
import os
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
# Defaults are not specified since both keys are required.
features={
'image_raw': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenFeature([], tf.int64),
'height': tf.FixedLenFeature([], tf.int64),
'width': tf.FixedLenFeature([], tf.int64),
'depth': tf.FixedLenFeature([], tf.int64)
})
image = tf.decode_raw(features['image_raw'], tf.uint8)
label = tf.cast(features['label'], tf.int32)
height = tf.cast(features['height'], tf.int32)
width = tf.cast(features['width'], tf.int32)
depth = tf.cast(features['depth'], tf.int32)
return image, label, …Run Code Online (Sandbox Code Playgroud) init_op = tf.global_variables_initializer()
Run Code Online (Sandbox Code Playgroud)
在定义任何变量或操作之前,然后得到一个错误
Attempting to use uninitialized value
Run Code Online (Sandbox Code Playgroud)
这里有一个解释,但它没有提到底层tf.global_variables_initializer调用.它几乎复制TF API批发.这个问题集中在一些用户呼叫时仍然存在未初始化的值这一事实sess.run(init_op).示例代码和对什么tf.global_variables_initializer是伟大的分析.
我指的是扩张卷积的多尺度上下文聚合.
我可以清楚地看到,这允许您有效地使用4个参数,但具有3x3和9个参数的感受域,但具有5x5的感受野.
扩张卷积的情况是简单地保存参数,同时获得更大的感受野的好处,从而节省内存和计算?
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
# Defaults are not specified since both keys are required.
features={
'image_raw': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenFeature([], tf.int64),
'height': tf.FixedLenFeature([], tf.int64),
'width': tf.FixedLenFeature([], tf.int64),
'depth': tf.FixedLenFeature([], tf.int64)
})
# height = tf.cast(features['height'],tf.int32)
image = tf.decode_raw(features['image_raw'], tf.uint8)
image = tf.reshape(image,[32, 32, 3])
image = tf.cast(image,tf.float32)
label = tf.cast(features['label'], tf.int32)
return image, label
Run Code Online (Sandbox Code Playgroud)
我正在使用TFRecord来存储我的所有数据.函数read_and_decode来自TensorFlow提供的TFRecords示例.目前我通过预定义的值重塑:
image = tf.reshape(image,[32, 32, 3])
Run Code Online (Sandbox Code Playgroud)
但是,我现在使用的数据具有不同的尺寸.例如,我可以有一个[40,30,3]的图像(缩放这不是一个选项,因为我不希望它被扭曲).我想阅读不同维度的数据,并在数据扩充阶段使用random_crop来规避这个问题.我需要的是以下内容.
height = tf.cast(features['height'], tf.int32)
width = tf.cast(features['width'], tf.int32)
image = …Run Code Online (Sandbox Code Playgroud) 类似于如何在TensorFlow中访问protos中的值?但不适合这种情况.
我bytes tensor_content在TensorProto中看到了一个属性.我正试图通过以下方式获取有关节点的信息:
for node in tf.get_default_graph().as_graph_def().node:
node.attr['value'].tensor.tensor_content # decode these bytes
有关信息,节点的打印如下所示:
name: "conv2d/convolution/Shape"
op: "Const"
device: "/device:GPU:0"
attr {
key: "dtype"
value {
type: DT_INT32
}
}
attr {
key: "value"
value {
tensor {
dtype: DT_INT32
tensor_shape {
dim {
size: 4
}
}
tensor_content: "\003\000\000\000\003\000\000\000\001\000\000\000 \000\000\000"
}
}
}
Run Code Online (Sandbox Code Playgroud) import tensorflow as tf
# construct graph
v1 = tf.Variable([0], name='v1')
v2 = tf.Variable([0], name='v2')
# run graph
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver()
saver.save(sess, 'ckp')
Run Code Online (Sandbox Code Playgroud)
索引文件和数据文件是什么关系?
.
??? checkpoint
??? ckp.data-00000-of-00001
??? ckp.index
??? ckp.meta
Run Code Online (Sandbox Code Playgroud)