首先,我知道这里有一个相关的问题.
但是,这个问题是关于实施和内部的.我正在阅读论文" TensorFlow之旅 ".从那里引用以下两点:
1.
张量本身不会在内存中保存或存储值,但仅提供用于检索张量引用的值的接口.
这告诉我,Tensor是一个简单地将指针存储到操作结果的对象,并且在检索张量的结果或值时,它只是取消引用该指针.
2.
变量可以描述为存储张量的内存缓冲区的持久可变句柄.因此,变量的特征在于某种形状和固定类型.
在此我感到困惑,因为我认为,基于前一点,Tensors只存储一个指针.如果它们只是指针,它们也可能是可变的.
确切地说,这些是我的问题:
我知道在TensorFlow中,tf.string张量基本上是一个字节字符串.我需要使用tf.train.string_input_producer()存储在队列中的文件名进行一些操作.
下面显示了一个小片段:
key, value = reader.read(filename_queue)
filename = value.eval(session=sess)
print(filename)
Run Code Online (Sandbox Code Playgroud)
但是,作为字节字符串,它提供如下输出:
b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08'
Run Code Online (Sandbox Code Playgroud)
我试着转换使用
filename = tf.decode_raw(filename, tf.uint8)
filename = ''.join(chr(i) for i in filename)
Run Code Online (Sandbox Code Playgroud)
但是Tensor对象不可迭代,因此失败.
我哪里错了?
它是TensorFlow中缺少的一个特性,tf.string可以很容易地转换为Python字符串,还是有其他一些我不知道的功能?
更多信息
filename_queue的编写如下:
train_set = ['file1.jpg', 'file2.jpg'] # Truncated for illustration
filename_queue = tf.train.string_input_producer(train_set, num_epochs=10, seed=0, capacity=1000)
Run Code Online (Sandbox Code Playgroud) 我试图解决的问题如下:我有一个trainimgs文件名列表.我已经定义了一个
tf.RandomShuffleQueue与它capacity=len(trainimgs)和min_after_dequeue=0.tf.RandomShuffleQueue预计这将填充trainimgs指定epochlimit的次数.tf.RandomShuffleQueue并对其进行一些操作并将其排入另一个队列.我有那个部分是正确的.1 epoch的trainimgs已被处理和tf.RandomShuffleQueue为空,前提是当前时期e < epochlimit,队列必须再次被填满和线程必须重新工作.好消息是:我已经让它在某种情况下工作(最后见PS !!)
坏消息是:我认为有更好的方法可以做到这一点.
我现在使用的方法如下(我已经简化了功能并删除了基于预处理和后续排队的e图像处理,但处理的核心保持不变!!):
with tf.Session() as sess:
train_filename_queue = tf.RandomShuffleQueue(capacity=len(trainimgs), min_after_dequeue=0, dtypes=tf.string, seed=0)
queue_size = train_filename_queue.size()
trainimgtensor = tf.constant(trainimgs)
close_queue = train_filename_queue.close()
epoch = tf.Variable(initial_value=1, trainable=False, dtype=tf.int32)
incrementepoch = tf.assign(epoch, epoch + 1, use_locking=True)
supplyimages = train_filename_queue.enqueue_many(trainimgtensor)
value = train_filename_queue.dequeue()
init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
sess.run(init_op)
coord = tf.train.Coordinator() …Run Code Online (Sandbox Code Playgroud) 在TensorFlow中,getter的概念和用途是什么?
签名tf.get_variable()是:
get_variable(
name,
shape=None,
dtype=None,
initializer=None,
regularizer=None,
trainable=True,
collections=None,
caching_device=None,
partitioner=None,
validate_shape=True,
use_resource=None,
custom_getter=None
)
Run Code Online (Sandbox Code Playgroud)
文件中的定义custom_getter如下:
custom_getter: Callable,它将第一个参数作为true getter,并允许覆盖内部get_variable方法.custom_getter的签名应与此方法的签名相匹配,但最适合未来的版本将允许更改:def custom_getter(getter,*args,**kwargs).也允许直接访问所有get_variable参数:def custom_getter(getter,name,*args,**kwargs).一个简单的身份自定义getter只需创建具有修改名称的变量是:python def custom_getter(getter,name,*args,**kwargs):return getter(name +'_suffix',*args,**kwargs)
不幸的是,它不是很清楚.有人可以请进行扩展吗?
我试图理解这种分裂方法的逻辑过程.
我们可以从中获得多大的分割质量?这是拆分数据集的推荐方法吗?
# We want to ignore anything after '_nohash_' in the file name when
# deciding which set to put an image in, the data set creator has a way of
# grouping photos that are close variations of each other. For example
# this is used in the plant disease data set to group multiple pictures of
# the same leaf.
hash_name = re.sub(r'_nohash_.*$', '', file_name)
# This looks …Run Code Online (Sandbox Code Playgroud)我编写了一个TensorFlow代码,并使用生成了时间线图tensorflow.python.client.timeline。但是我不清楚如何解释时间轴和理解代码中的瓶颈。目前,我刚刚编写了一个基于CPU的基本数据增强代码,但是有关如何解释绘图的一些帮助将非常有帮助。
使用的TensorFlow版本:v1.1(从来源编译)
我的代码如下:
import tensorflow as tf
from tensorflow.python.client import timeline
import matplotlib.pyplot as plt
def coloraugment(image):
output = tf.image.random_brightness(image, max_delta=100./255.)
output = tf.clip_by_value(output, 0.0, 1.0)
output = tf.image.random_saturation(output, lower=0.2, upper=2)
output = tf.clip_by_value(output, 0.0, 1.0)
output = tf.image.random_contrast(output, lower=0.2, upper=2)
output = tf.clip_by_value(output, 0.0, 1.0)
return output
def augmentbody(image, sz):
for i in range(5):
if i == 0:
cropped = tf.random_crop(value=image, size=sz)
croppedflipped = tf.image.flip_left_right(cropped)
out = tf.stack([cropped, croppedflipped], axis=0)
else:
cropimg = tf.random_crop(value=image, size=sz)
augcolor = …Run Code Online (Sandbox Code Playgroud) 我想简单地定义一个模型,并在TensorBoard中可视化其图形以进行初始体系结构检查。因此,我不想为此目的进行任何计算。
在TensorFlow 1.X中,在一个tf.Session()我可以简单地flush()编写摘要文件的地方轻松实现。
在TensorFlow 2.0中没有tf.Session(),因此问题是如何实现呢?
以下是示例代码。为了在TensorBoard中编写图结构,我需要添加什么?
from nets import i3d
import tensorflow as tf
def i3d_output(model, x):
out, _ = model(x)
return out
tf.compat.v1.disable_eager_execution()
x = tf.random.uniform(shape=(4,179,224,224,3))
model = i3d.InceptionI3d()
net = i3d_output(model, x)
train_summary_writer = tf.summary.create_file_writer('/home/uujjwal/bmvc2019')
Run Code Online (Sandbox Code Playgroud) 我tf.layers.conv2d在TensorFlow V1.0中使用进行卷积.
一个例子如下:
conv1 = tf.layers.conv2d(batch_images, filters=96,
kernel_size=7,
strides=2,
activation=tf.nn.relu,
kernel_initializer=tf.contrib.layers.xavier_initializer_conv2d(uniform=False),
bias_initializer=tf.contrib.layers.xavier_initializer(uniform=False),
kernel_regularizer=tf.nn.l2_loss,
bias_regularizer=tf.nn.l2_loss,
name='conv1')
Run Code Online (Sandbox Code Playgroud)
然后我尝试按如下方式收集过滤器重量: -
l1weights = tf.get_collection(tf.GraphKeys.WEIGHTS, 'conv1')
Run Code Online (Sandbox Code Playgroud)
然而,虽然网络正在接受培训,但我还是会[]在l1weights会话中进行评估.
如何提取滤镜权重并使用它来显示它们tf.summary.image?
我想使用多个进程(not threads)进行一些预处理并将结果排入tf.RandomShuffleQueue,我的主图可以使用它来进行训练.
有没有办法做到这一点 ?
我已将我的数据集转换为分割为256个分片的TFRecords.我想开始使用20个进程multiprocessing,让每个进程处理一系列分片.每个过程都应该读取图像,然后对它们进行扩充并将它们推入一个tf.RandomShuffleQueue可以将输入提供给图形进行训练的图像.
有人建议我通过这个inception例子tensorflow.但是,这是一种非常不同的情况,因为只有数据分片的读取是由多个线程(not processes)完成的,而预处理(例如 - 扩充)是在主线程中进行的.
当我运行培训时,我的预处理示例已成功创建,但是我的培训没有开始。事实很奇怪,在分析我的TensorBoard图时,我看到一些额外的条件节点,它们在代码中不存在。我想知道这些额外的节点在何处以及为什么会出现,以及为什么培训没有开始。以下是对情况的系统描述:
TensorFlow图
下面的TensorBoard图显示了我的图:
构造此图的代码如下
def getconv2drelu(inputtensor, kernelsize, strides, padding, convname,
imagesummaries=False):
weights = tf.get_variable("weights", shape=kernelsize, dtype=tf.float32,
initializer=tf.truncated_normal_initializer(0,
0.01),
regularizer=tf.nn.l2_loss)
biases = tf.get_variable("biases", shape=kernelsize[3], dtype=tf.float32,
initializer=tf.constant_initializer(0.0))
conv = tf.nn.conv2d(input=inputtensor, filter=weights, strides=strides,
padding=padding, name=convname)
response = tf.nn.bias_add(conv, biases)
if imagesummaries:
filters = (weights - tf.reduce_min(weights)) / (tf.reduce_max(
weights) - tf.reduce_min(weights))
filters = tf.transpose(filters, [3, 0, 1, 2])
tf.summary.image(convname + " filters", filters,
max_outputs=kernelsize[3])
response = tf.nn.relu(response)
activation_summary(response)
return response
def getfullyconnected(inputtensor, numinput, numoutput):
weights = tf.get_variable("weights", shape=[numinput, numoutput],
dtype=tf.float32,
initializer=
tf.truncated_normal_initializer(0, …Run Code Online (Sandbox Code Playgroud) 我尽最大努力发现,如果不使用 docker,就无法安装 TensorFlow 服务。是否使用与 TensorFlow Serving 牢固嵌入的 docker,或者是否有解决方法?
为什么 TFRecords 文件在 TensorFlow 的初始模型示例中被分片?
对于随机性,在创建单个 TFRecord 文件之前不能对文件列表进行打乱吗?