小编Tim*_*man的帖子

在TensorFlow中对数组进行排序

假设我在TensorFlow中有一个数组:

[ 0.12300211,  0.51767069,  0.13886075,  0.55363625],
[ 0.47279349,  0.50432992,  0.48080254,  0.51576483],
[ 0.84347934,  0.44505221,  0.88839239,  0.48857492],
[ 0.93650454,  0.43652734,  0.96464157,  0.47236174], ..
Run Code Online (Sandbox Code Playgroud)

我想在第三列对这个数组进行排序.我该怎么做呢?我能够使用单独对每列进行排序tf.nn.top_k(),这为我提供了排序值和相应的索引.我可以使用第三列的索引对其他列重新排序,但我找不到重新排序的Op.

假设我想保持图形内容(没有Python恶作剧):

  • 如何在TensorFlow中对(上面的数组)进行排序?
  • 当我有重新订购的索引时,如何在TensorFlow中重新订购?

python arrays sorting tensorflow

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

Tensorflow的非对称填充假设

为什么选择Tensorflow更喜欢右下角的填充?使用'SAME'填充,对我来说,在第一个真实像素处启动内核的中心锚点会合乎逻辑.由于使用了不对称填充,这导致与其他一些框架的差异.我确实理解非对称填充原则上是好的,否则将留下未使用的填充行/列.

如果Tensorflow会优先考虑左侧和顶部的填充,那么它将进行卷积和权重与Caffe/cudnn/$ frameworks相同,并且无论填充如何,权重转换都是兼容的.

TF给出了底部和右边填充优先级

码:

import numpy as np
import tensorflow as tf
import torch
import torch.nn as nn

tf.enable_eager_execution()

def conv1d_tf(data, kernel_weights, stride):
    filters = np.reshape(kernel_weights, [len(kernel_weights), 1, 1])
    out = tf.nn.conv1d(
        value=data,
        filters=filters,
        stride=stride,
        padding='SAME',
        data_format='NCW',
        )
    return out


def conv1d_pytorch(data, kernel_weights, stride):
    filters = np.reshape(kernel_weights, [1, 1, len(kernel_weights)])
    kernel_size = len(kernel_weights)
    size = data.shape[-1]
    def same_padding(size, kernel_size, stride, dilation):
        padding = ((size - 1) * (stride - 1) + dilation * (kernel_size - 1)) //2
        return padding
    padding …
Run Code Online (Sandbox Code Playgroud)

padding convolution caffe tensorflow

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

Tensorflow数据输入切换:训练/验证

从方便但速度较慢的占位符切换后,我有通过队列运行器进入图表的数据。

在每个培训时期之后,我希望运行一个验证通行证。除训练通行证外,验证通行证使用不同的数据,没有扩充,也没有改组。

问题很简单:如何切换这些内容?

一些观察:

  • 我无法通过布尔值来切换shuffle选项。string_input_producertf.placeholder
  • 我发现的唯一的在线示例使用placeholder来将训练与验证数据分开。这些依次不使用高级队列运行器。
  • 我确实设法通过上述操作完成上述操作,tf.cond()我将测试通过的is_training tf.placeholder布尔值feed_dict。这种解决方案是最佳的吗?这种tf.conf()方法多少钱?

python tensorflow

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

在不启动会话的情况下检查TFRecordReader条目

让我们假设我写了一个带有MNIST示例的TFRecords文件(https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/how_tos/reading_data/convert_to_records.py)这样做是这样的:

writer = tf.python_io.TFRecordWriter(filename)
  for index in range(num_examples):
    image_raw = images[index].tostring()
    example = tf.train.Example(features=tf.train.Features(feature={
        'height': _int64_feature(rows),
        'width': _int64_feature(cols),
        'depth': _int64_feature(depth),
        'label': _int64_feature(int(labels[index])),
        'image_raw': _bytes_feature(image_raw)}))
    writer.write(example.SerializeToString())
  writer.close()
Run Code Online (Sandbox Code Playgroud)

然后在其他一些脚本中加载它.但我找到的唯一方法是将它作为张量运行并提取数据,其中r一个是来自迭代器的记录record_iter = tf.python_io.tf_record_iterator(db_path)

    with tf.Session() as sess_tmp:
        single_ex = (sess_tmp.run(tf.parse_single_example(r,features={
            'height': tf.FixedLenFeature([], tf.int64),
            'width': tf.FixedLenFeature([], tf.int64),
            'depth': tf.FixedLenFeature([], tf.int64),
            'image_raw': tf.FixedLenFeature([], tf.string),
            'label': tf.FixedLenFeature([], tf.int64),
        })))
Run Code Online (Sandbox Code Playgroud)

然后可以single_ex['height']例如检索数据.但是,在我看来,必须有一个更简单的方法.我似乎无法找到相应的.proto来检索数据.而数据肯定在那里.这是一个转储r:

?
?
    image_raw?
?
?&00>a?????????????(??Y??aC\?z??;??\????\e?\i???
                                                ??)L???^
?y????~??a???4??G??<????.M???n???t????VB??<????Z???\?????,I??

depth


label


width


height
Run Code Online (Sandbox Code Playgroud)

python tensorflow

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

Tensorflow - 获取队列中的样本数量?

对于性能监控,我想关注当前排队的示例.我正在平衡我用于填充队列的线程数量以及队列的最佳最大大小.我如何获得这些信息?我正在使用tf.train.batch(),但我想这些信息可能会在某个地方出现FIFOQueue?我原以为这是一个局部变量,但我还没有找到它.

python tensorflow

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

标签 统计

tensorflow ×5

python ×4

arrays ×1

caffe ×1

convolution ×1

padding ×1

sorting ×1