运行# --coding:utf-8-- import torch from utils.loadingutils import loadmodel, getdevice…
- User
运行# --coding:utf-8-- import torch from utils.loading_utils import load_model, get_device import numpy as np import argparse import pandas as pd import os import cv2 import pdb
the following functions are borrowed from: https://github.com/uzh-rpg/rpg_e2vid
from utils.event_readers import FixedSizeEventReader, FixedDurationEventReader from utils.inference_utils import events_to_voxel_grid, events_to_voxel_grid_pytorch from utils.timers import Timer
import time from image_reconstructor import ImageReconstructor from options.inference_options import set_inference_options from PIL import Image from dv import AedatFile
def extract_davis(aedat_file_path, dvs_img_interval): frame_no = 0 frame_all = [] frame_exposure_time = [] frame_interval_time = [] # use_mode = 'frame_exposure_time' #### default mode use_mode = 'frame_interval_time' with AedatFile(aedat_file_path) as f: # list all the names of streams in the file print(f.names) # extract timestamps of each frame for frame in f['frames']: frame_all.append(frame.image) frame_exposure_time.append([frame.timestamp_start_of_exposure, frame.timestamp_end_of_exposure]) ## [1607928583397102, 1607928583401102] frame_interval_time.append( [frame.timestamp_start_of_frame, frame.timestamp_end_of_frame]) ## [1607928583387944, 1607928583410285]
code# pdb.set_trace() if use_mode == 'frame_exposure_time': frame_timestamp = frame_exposure_time elif use_mode == 'frame_interval_time': frame_timestamp = frame_interval_time frame_num = len(frame_timestamp) # Access dimensions of the event stream height, width = f['events'].size # 260 346 event_frame = 255 * np.ones((height, width, 3), dtype=np.uint8) # loop through the "events" stream # events = np.hstack([packet for packet in f['events'].numpy()]) # # Access information of all events by type # timestamps, x, y, polarities = events['timestamp'], events['x'], events['y'], events['polarity'] # pdb.set_trace() # save event_img idx = np.round(np.linspace(0, len(frame_timestamp) - 1, int(frame_num / dvs_img_interval))).astype( int) ## frame index [0, 1, 2, ... , 3847] frame_timestamp = np.array(frame_timestamp)[idx] ## (3848, 2) # another reader # speed up # events will be a named numpy array events = np.hstack([packet for packet in f['events'].numpy()]) timestamps, x, y, polarities = events['timestamp'], events['x'], events['y'], events['polarity'] return timestamps, x, y, polarities, frame_num, frame_timestamp ####################################################################################################### - Assistant
在你提供的代码中,有一个调用到
update_reconstruction方法的部分,在这里报错提示参数数量不匹配。错误表明该方法只接受 3 或 4 个参数,但是在调用时使用了 6 个参数。首先需要检查
ImageReconstructor类的定义中的update_reconstruction方法,看看具体接受多少个参数,并且什么样的参数是必需的。根据错误提示,方法调用传递了以下六个参数:- event_tensor
- start_index + num_events_in_window
- last_timestamp
- frame_no
- save_img_path
我们需要调整该方法调用以匹配
update_reconstruction方法定义的参数格式。如果你有ImageReconstructor类的定义代码,你应该查看或修改此方法的参数,使代码运行不出错。如果按照通常的假设和上下文分析,可能的调整大致如下:- 假设
update_reconstruction应该只处理关于重建和保存图片的逻辑,它可能不需要start_index + num_events_in_window和last_timestamp这两个参数。
调整后的调用可能像这样(假设只需要事件张量、帧编号和保存路径):
pythonreconstructor.update_reconstruction(event_tensor, frame_no, save_img_path)请确保你拿代码段里的
update_reconstruction定义来调整此段代码,以避免类似的错误。此外,这个错误调试过程假设
update_reconstruction方法签名可能像这样:pythondef update_reconstruction(self, event_tensor, frame_no, save_path): ... - User
- Assistant
谢谢你提供
ImageReconstructor类的代码。根据你提供的这个类的定义,我们可以分析update_reconstruction需要的正确参数。方法签名为:pythondef update_reconstruction(self, event_tensor, event_tensor_id, stamp=None):这个方法接受三个参数:
event_tensor,event_tensor_id和可选的stamp。目前在你的主程序中对此函数的调用传递了太多的参数,而且参数的类型和功能看起来也有些错误。让我们修改主程序中对这个方法的调用,以确保只传递正确的参数。根据当前的
ImageReconstructor类定义,正确的调用应该是这样的:pythonreconstructor.update_reconstruction(event_tensor, frame_no)其中
frame_no作为event_tensor_id参数传入,event_tensor为之前你构建好的事件张量。可选的stamp参数在此场景中看起来不是必须的,除非你有特定的时间戳信息需要处理。在你之前的调用中,传入的参数如下:
pythonreconstructor.update_reconstruction(event_tensor, start_index + num_events_in_window, last_timestamp, frame_no, save_img_path)这显然是不正确的,并且根据函数定义,此函数内部还处理了许多与重构有关的步骤如处理GPU Tensor的转换、应用滤波器等,这可能需要根据你具体的需求对传入的参数进行微调。
因此,请更改你的代码以传递正确的参数至 。如果你有任何其他的功能需求或进一步的问题,请随时提出。
- User
如果我们不改 reconstructor.update_reconstruction(event_tensor, start_index + num_events_in_window, last_timestamp, frame_no, save_img_path),那么应该如何修改update_reconstruction?
- Assistant
如果你希望保持当前对
update_reconstruction方法的调用参数不变,你需要修改ImageReconstructor类中的 方法来接受额外的参数。根据你提供的当前方法调用,我们可以调整此方法以接受以下参数: