aedat_file_path = os.path.join(data_path, foldName, foldName+'.aedat4')
save_img_path = os.path.join(save_path, foldName, foldName+'_recon')
if not os.path.exists(save_img_path):
os.makedirs(save_img_path)
# dvs_img_interval = 1
# for root, dirs, files in os.walk(aedat_path):
# for file in files:
# (filename, extension) = os.path.splitext(file)
# print("==>> filename: ", filename)
# if (extension == '.aedat4'):
# if filename + '_aps' in os.listdir(root) or filename + '_dvs' in os.listdir(root):
# print("==>> Skip this video ... ")
# continue
# save_path_dvs = os.path.join(root, filename, filename+'_dvs')
# save_path_aps = os.path.join(root, filename, filename+'_aps')
# aedat_file_path = os.path.join(root, filename + '.aedat4')
# filename_txt_path = os.path.join(root, filename+'_timestamp.txt')
# croped_events_path = os.path.join(root, filename+'_events.txt')
# if not os.path.exists(save_path_dvs):
# os.makedirs(save_path_dvs)
# if not os.path.exists(save_path_aps):
# os.makedirs(save_path_aps)
timestamps, x, y, polarities, frame_num, frame_timestamp = extract_davis(aedat_file_path, 1) ## (4391964,)
# all_events = [timestamps, x, y, polarities]
all_events = np.zeros((timestamps.shape[0], 4))
all_events[:, 0] = timestamps
all_events[:, 1] = x
all_events[:, 2] = y
all_events[:, 3] = polarities
# pdb.set_trace()
parser = argparse.ArgumentParser(description='Evaluating a trained network')
parser.add_argument('-c', '--path_to_model', required=True, type=str, help='path to model weights')
parser.add_argument('-i', '--input_file', required=False, type=str)
parser.add_argument('--fixed_duration', dest='fixed_duration', action='store_true')
parser.set_defaults(fixed_duration=False)
parser.add_argument('-N', '--window_size', default=500000, type=int,
help="Size of each event window, in number of events. Ignored if --fixed_duration=True")
parser.add_argument('-T', '--window_duration', default=33.33, type=float,
help="Duration of each event window, in milliseconds. Ignored if --fixed_duration=False")
parser.add_argument('--num_events_per_pixel', default=0.35, type=float,
help='in case N (window size) is not specified, it will be automatically computed as N = width * height * num_events_per_pixel')
parser.add_argument('--skipevents', default=0, type=int)
parser.add_argument('--suboffset', default=0, type=int)
parser.add_argument('--compute_voxel_grid_on_cpu', dest='compute_voxel_grid_on_cpu',
action='store_true')
parser.set_defaults(compute_voxel_grid_on_cpu=False)
set_inference_options(parser)
args = parser.parse_args()
# Load model
device = get_device(args.use_gpu)
model = load_model(args.path_to_model)
model = model.to(device)
model.eval()
# pdb.set_trace()
height, width = 260, 346
reconstructor = ImageReconstructor(model, height, width, model.num_bins, args)
start_s = 0
""" Read chunks of events using Pandas """
for frame_no in range(0, frame_num-1):
# Loop through the events and reconstruct images
N = frame_timestamp[frame_no][1] - frame_timestamp[frame_no][0]
# if not args.fixed_duration:
# if N is None:
# N = int(width * height * args.num_events_per_pixel)
# print(
# 'Will use {} events per tensor (automatically estimated with num_events_per_pixel={:0.2f}).'.format(
# N, args.num_events_per_pixel))
# else:
# print('Will use {} events per tensor (user-specified)'.format(N))
# mean_num_events_per_pixel = float(N) / float(width * height)
# if mean_num_events_per_pixel < 0.1:
# print('!!Warning!! the number of events used ({}) seems to be low compared to the sensor size. \
# The reconstruction results might be suboptimal.'.format(N))
# elif mean_num_events_per_pixel > 1.5:
# print('!!Warning!! the number of events used ({}) seems to be high compared to the sensor size. \
# The reconstruction results might be suboptimal.'.format(N))
initial_offset = args.skipevents
sub_offset = args.suboffset
start_index = initial_offset + sub_offset
if args.compute_voxel_grid_on_cpu:
print('Will compute voxel grid on CPU.')
with Timer('Processing entire dataset'):
# event_window = all_events[:N, :]
# event_window = all_events[start_s: start_s+N, :]
# last_timestamp = event_window[-1, 0]
# start_s += N
start_idx = np.where(all_events[:, 0] >= frame_timestamp[frame_no][0])[0][0]
end_idx = np.where(all_events[:, 0] >= frame_timestamp[frame_no][1])[0][0]
event_window = all_events[start_idx:end_idx]
last_timestamp = event_window[-1, 0]
with Timer('Building event tensor'):
if args.compute_voxel_grid_on_cpu:
# pdb.set_trace()
event_tensor = events_to_voxel_grid(event_window, num_bins=model.num_bins, width=width,
height=height)
event_tensor = torch.from_numpy(event_tensor)
else:
# pdb.set_trace()
event_tensor = events_to_voxel_grid_pytorch(event_window, num_bins=model.num_bins,
width=width, height=height, device=device)
num_events_in_window = event_window.shape[0]
reconstructor.update_reconstruction(event_tensor, start_index + num_events_in_window,
last_timestamp, frame_no, save_img_path)
start_index += num_events_in_window 训练时,报错:Loading model /data2/local_userdata/heyuting/Projects1/项目/CEUTrack/scripts/rpg_e2vid/pretrained/E2VID_lightweight.pth.tar...
The error you're encountering is caused by a mismatch between the expected and provided arguments to the update_reconstruction method in the ImageReconstructor class. The method is called with 6 arguments, which seems incorrect based on the error message indicating it expects between 3 to 4 arguments.
To resolve the issue, you need to review the ImageReconstructor class definition, specifically the update_reconstruction method, to understand what parameters it actually requires. Then, you can modify the call to match this requirement.
Based on typical usage, I’ll make a logical assumption about what parameters might be expected (although you should verify this against your actual class definition):
event_tensor: The voxel grid or event tensor to be processed.
timestamp: The timestamp associated with the current frame or event block you're processing.
frame_no: An index or identifier for the frame.
save_img_path: The directory path where the reconstructed image will be saved.
Without the exact method signature from the class definition, I can only guess. Here's how you might adjust the call based on common parameters:
# In your main loop where you call `update_reconstruction`
for frame_no in range(0, frame_num - 1):
...
with Timer('Building event tensor'):
...
last_timestamp = event_window[-1, 0]
with Timer('Reconstructing image'):
reconstructor.update_reconstruction(event_tensor, last_timestamp, frame_no, save_img_path)
Ensure the following:
-
Method Signature Verification: Open the ImageReconstructor class and check the definition of update_reconstruction. Align the parameters in your call with those required by the method signature.
-
Class and Method Definitions: Ensure there are no overloads or dynamic parameter settings within the class that could confuse which method or parameters are being used.
-
Data Types and Formats: Ensure that all data passed to the method conforms to the expected types and structures (e.g., event_tensor as a Torch tensor, last_timestamp as a float or integer).
-
Error Handling: Consider adding more specific error handling around critical method calls to provide clearer feedback if something goes wrong.
-
Logging and Debugging: Adding more detailed logging before and after significant operations could help track down the flow of data and the operations being performed, giving you more insight if further issues arise.
By doing this, you should be able to resolve the current error and ensure your application correctly processes each frame as expected. If more issues arise, checking parameter passing, method definitions, and ensuring consistent data handling are all effective debugging steps.