【问题标题】:Is there a way to create my own batch of images?有没有办法创建我自己的一批图像?
【发布时间】:2020-09-27 20:56:44
【问题描述】:

我构建了一个卷积神经网络模型,我想使用真实的实时摄像头对其进行测试。如果我逐帧输入肯定不会起作用,因为 CNN 架构的输入形状与单个帧不匹配。例如网络的输入应该是这样的

(50000, 32, 32, 3)

但是像这样的单帧形状

(32, 32, 3)

所以我想知道是否有办法创建一批帧,比如将每 5 个帧放在一起,用模型测试它们,然后再取出接下来的 5 个帧等等?或者重复每一帧并将它们放在一起进行测试。我不知道这是可能的还是有更好的方法。谢谢

【问题讨论】:

    标签: python-3.x opencv deep-learning conv-neural-network


    【解决方案1】:

    这可以通过自定义数据集来实现。像这样的。

    class Live_Video_Dataset(Dataset):
    
    def __init__(self, transform=None):
        self.transform = transform
        self.video_buffer = []
        self.video_buffer_length
    
        # Here fill the video buffer with fremes from the camera asyncronusly.
    
    def __len__(self):
        return self.video_buffer_length
    
    def __getitem__(self, idx):
    
        if video_buffer[idx] == None
            # Handle Exception
        else:
            sample = video_buffer[idx]
            if self.transform:
                sample = self.transform(sample)
    
            return sample
    

    由于您没有指定您使用的 ML 框架,我假设您使用的是 PyTorch。但我认为逻辑很清楚,您可以将其适应任何 ML 框架。希望能帮助到你。祝你好运。

    【讨论】:

      【解决方案2】:

      我认为你的意思是:

      f0 = np.zeros((32, 32, 3), dtype=np.uint8)
      f1 = np.zeros((32, 32, 3), dtype=np.uint8) + 1
      f2 = np.zeros((32, 32, 3), dtype=np.uint8) + 2
      f3 = np.zeros((32, 32, 3), dtype=np.uint8) + 3
      f4 = np.zeros((32, 32, 3), dtype=np.uint8) + 4
      
      arrayOfArrays = np.array([f0,f1,f2,f3,f4])
      
      print(arrayOfArrays.shape)
      (5,32,32,3)
      

      【讨论】:

        猜你喜欢
        • 2012-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多