有没有像x.toPixels tensorflowjs函数那样的python tensorflow/pythorch函数



我需要一个tf.browser.toPixels() tensorflowJS函数的替换项。试图将一些代码移植到python,我想知道是否有一种快速的方法可以解决这个问题。

在浏览器中,这变得非常简单,我们只需回调新的帧并绘制到画布中。但在python开发中,比如说在matplotlibtkinter中,我想我需要一些技巧。

有没有(不是超级大的(解决方案?感谢

假设您有一个2D张量img,它像tf.browser.toPixels(img)一样在浏览器中运行。您可以使用OpenCVmatplotlib绘制类似的图像,如:

  • 使用Pytorch
import matplotlib.pyplot as plt
# If your data is in GPU:
img_np = img.cpu().numpy()
# Using OpenCV
cv2.imwrite(img_np.astype(np.uint8), "image.png")
# Using matplotlib
plt.imshow(img_np)
  • Tensorflow
```python
import matplotlib.pyplot as plt
img_np = img.numpy()
# Using OpenCV
cv2.imwrite(img_np.astype(np.uint8), "image.png")
# Using matplotlib
plt.imshow(img_np)

此外,如果你有一个3D张量(即n x m x 3(,你仍然可以对波段进行平均,并用它制作一个2D张量,并以同样的方式绘制它们。

最新更新