在 TF 2.0 Beta 中,我正在尝试:
x = tf.keras.layers.Input(shape=(240, 2), dtype=tf.float32)
print(x.shape) # (None, 240, 2)
a = x[:, :, 0]
print(a.shape) # <unknown>
Run Code Online (Sandbox Code Playgroud)
在 TF 1.x 中,我可以这样做:
x = tf1.placeholder(tf1.float32, (None, 240, 2)
a = x[:, :, 0]
Run Code Online (Sandbox Code Playgroud)
它会正常工作。我如何在 TF 2.0 中实现这一点?我认为
tf.split(x, 2, axis=2)
Run Code Online (Sandbox Code Playgroud)
可能有用,但是我想使用切片而不是硬编码 2(轴 2 的尺寸)。
我曾经使用scipy将文件中的图像直接加载到ndarray中.
from scipy import misc
img = misc.imread('./myimage.jpg')
type(img)
>>> numpy.ndarray
Run Code Online (Sandbox Code Playgroud)
但是现在它给了我一个DeprecationWarning,并且文档说它将在1.2.0中删除.而我应该使用imageio.imread.但:
import imageio
img = imageio.imread('./myimage.jpg')
type(img)
>>> imageio.core.util.Image
Run Code Online (Sandbox Code Playgroud)
我可以通过做转换它
img = numpy.array(img)
Run Code Online (Sandbox Code Playgroud)
但这看起来很糟糕.有没有办法将图像直接加载到numpy数组中,就像我之前使用scipy一样misc.imread(除了使用OpenCV)?
def foo():
x = np.ones((10,10))
return x[:5,:5]
Run Code Online (Sandbox Code Playgroud)
如果我调用,y = foo()我将得到一个 5x5 数组( 中值的 1/4 x)。但是 中的其他值会发生什么情况x,它们是否会保留在内存中或以某种方式被垃圾收集?我想了解这一点。
我有一个RecyclerView显示字符串的垂直列表:
Row0
Row1
Row2
Row3
Row4
...
Run Code Online (Sandbox Code Playgroud)
我正在使用该函数recyclerView.scrollToPosition(position);跳转到一行。但是,我想要跳转到的行最终位于视图的底部!
例如,如果我这样做,recyclerView.scrollToPosition(17);我会得到:
Row13
Row14
Row15
Row16
Row17 <--- 17 is at bottom (last visible row)
Run Code Online (Sandbox Code Playgroud)
我想要的是:
Row17 <-- 17 to be on top (first visible row)
Row18
Row19
Row20
Row21
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现这个目标?
python ×3
numpy ×2
android ×1
image ×1
java ×1
keras ×1
memory-leaks ×1
scipy ×1
tensorflow ×1