- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 3D 体积的输入数据,想对每个切片应用一个 ConvNet。
这个问题重复了。遗憾的是没有答案: How to slice a batch and apply an operation on each slice in TensorFlow
在 Keras 中我会使用 TimeDistributed层。在 Tensorflow 中,我找不到直接的等价物。相反,我觉得我必须自己对数据进行切片。
到目前为止,这是我的代码:
x=tf.placeholder(tf.float32, shape=[None, 40, 40, 40, 1])
slices=tf.split(0,40, x)
segmented_slices=[]
for slice in slices:
# apply a ConvNet to each slice
reshaped=tf.reshape(slice, (40, 40, 1)) #<-------second error
# reshaped=tf.reshape(slice, (None, 40, 40, 1)) #<-------third error
# segmented_slice=conv2d(slice, 3,1,32) #<-------first error
segmented_slice=conv2d(reshaped, 3,1,32)
segmented_slice=conv2d(segmented_slice, 3,32,32)
#... (more convolutions)
segmented_slices.append(segmented_slice)
volume=tf.concat(0, segmented_slices)
基本布局是split
-> ConvNet -> concat
。但是 split
保持维度。如果我只是将 slice
传递给卷积,它会提示:
ValueError: Shape (?, 40, 40, 40, 1) must have rank 4
因此我添加了一个整形。这确实减少了维数。但显然它也减少了 batch_size。与第一条错误信息相比,问号和前40个都没有了。
ValueError: Shape (40, 40, 1) must have rank 4
看来我需要在整形中保留 batch_size。我试图在元组中添加 None
。这会产生另一条错误消息:
TypeError: Expected int32, got None of type '_Message' instead.
这是正确的方法吗?我应该自己处理吗?
最佳答案
如果 Keras TimeDistributed Layer 是您所需要的,让我们看看它是如何实现的:
input_length = input_shape[1] # assume 2nd dim is the one to slice
# ...
# Shape: (num_samples * timesteps, ...)
inputs = K.reshape(inputs, (-1,) + input_shape[2:])
y = self.layer.call(inputs) # (num_samples * timesteps, ...)
# Shape: (num_samples, timesteps, ...)
output_shape = self.compute_output_shape(input_shape)
y = K.reshape(y, (-1, input_length) + output_shape[2:])
基本思想是以第一维和第二维(批处理和切片维)合并为一个的方式 reshape 张量。换句话说,每个“切片”都可以视为批处理中的一个附加数据点。然后将任何计算应用于这个新的虚拟批处理,并在最后 reshape 回原始形状。所有这些操作都可以在 Tensorflow 中轻松实现。
关于python - Tensorflow:切片数据并对每个切片应用卷积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40402050/
简而言之: 我怎样才能切片?也就是说,能够指定我想从多个索引(例如 y = x[(2, 5, 11)] )中提取,而不仅仅是单个索引(例如 y = x[2] )。 简单示例 : 说我有这个数据: d
是否可以在 F# 中对 Array2D 进行切片? 说,let tmp =Array2D.init 100 100 (fun x y -> x * 100 + y) 如何从 tmp 中检索某些列或某些
例如,我希望文本仅显示“此处”,但它不起作用。文本经常变化,但我需要的单词保持在固定位置。我想访问该词。 我做错了什么? function myFunction() { var x = doc
当尝试使用spring的分页或切片来迭代非常大的mongodb集合时,程序运行正常,但在某些时候下一页/切片为空,并且在调试时出现“包含未知实例的页面/切片”消息. 这是代码示例: do { Pa
有人能给我一个关于如何分割 ListView 的例子吗?我正在使用 SimpleCursorAdapter 在 ListView 中显示数据.. 我的代码是这样的。 private WordDbAda
这个问题在这里已经有了答案: C++ slicing causing leak / undefined behavior / crash (3 个答案) 关闭 8 年前。 如果我有如下代码: cla
这个问题在这里已经有了答案: Understanding slicing (38 个答案) 关闭 5 年前。 我目前有 500 行数据。我想使用前五十行,然后跳过 50 行,依此类推。我该如何继续这
为什么对一行或一列进行切片会产生“无量纲数组”?例如: import numpy as np arr = np.zeros((10,10)) print arr.shape # (10, 10) 但是
我有以下 pandas 数据框: Shortcut_Dimension_4_Code Stage_Code 10225003 2 8225003
如何通过数组为 ruby 中的散列创建切片,如下所示: info = { :key1 => "Lorem", :key2 => "something...", :key3 => "
这个问题在这里已经有了答案: regex to get all text outside of brackets (4 个答案) 关闭 5 年前。 我正在编写的这个程序接收到一个大小不同的字符串,其
我尝试使用 tf.Tensor.getitem 对张量进行切片功能如下: indices = [0, 5] data[:,:,indices] 但是我得到以下错误: TypeError: can on
这个问题在这里已经有了答案: Can I create a "view" on a Python list? (10 个答案) 关闭 7 年前。 有没有一种方法可以在 Python 3 中创建序列的
我想弄清楚如何从多维数组中获取单个维度(为了论证,假设它是二维的),我有一个多维数组: double[,] d = new double[,] { { 1, 2, 3, 4, 5 }, { 5, 4,
我有一个 std::vector。我想创建代表该 vector 切片的迭代器。我该怎么做?在伪 C++ 中: class InterestingType; void doSomething(slice
写在前面 前面的文章介绍了Go的一些基本类型,本文开始涉及Go的一些容器类型,它们都是可以包含多个元素的数据结构,如数组、切片、map 数组 数组是具有相同类型且长度固定的一组元素集合,定义的格式:v
给定一个 numpy 数组和一个 __getitem__ 类型的索引,是否有一种惯用的方法来获取数组的相应切片,总是返回一个数组而不是标量? 有效索引的示例包括:int、slice、省略号或上述的元组
我创建了一个继承自 pandas.DataFrame 的类。在此类中添加了元数据(不是添加到列中,而是添加到类实例中): class MeasurementPoint(pandas.DataFrame
我想在空间上剪切视频以生成 N x M 个文件。 例如,我想把 test.video 拆分成 NxM 的瓦片? Video tiles 最佳答案 您可以使用 ffmpeg 及其 crop filter
这是一个示例代码。比如我想拉德国 在页面加载时切片。在这段代码中,它拉取第一个切片。 无功图; var 传说; var chartData = [{ 国家:“立陶宛”, 值:260}, { 国家:“爱
我是一名优秀的程序员,十分优秀!