Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import name 'extract_image_by_index' from 'dsec_det.io' #1

Open
Bin1119 opened this issue Jun 4, 2024 · 1 comment
Open

Comments

@Bin1119
Copy link

Bin1119 commented Jun 4, 2024

It's a great job. But I got an error when running scripts/visualize_detections.py. I don't know if the code version needs to be updated.

Traceback (most recent call last):
  File "scripts/visualize_detections.py", line 8, in <module>
    from dsec_det.io import extract_from_h5_by_timewindow, extract_image_by_index, load_start_and_end_time
ImportError: cannot import name 'extract_image_by_index' from 'dsec_det.io' (/workspace/jb/dagr/libs/dsec-det/src/dsec_det/io.py)
@Zhang-JK
Copy link

Zhang-JK commented Jun 5, 2024

Same problem here. I tried to implement the missing functions as below for your reference. (Note that i only tested on the sample data and the function may be wrong)

in io.py:

def extract_image_by_index(image_list, idx):
    # use cv2 to read and return image
    return cv2.imread(str(image_list[idx]))
    
def load_start_and_end_time(dsec_directory):
    with h5py.File(str(dsec_directory.events.event_file), 'r') as h5f:
        t_offset = h5f['t_offset'][()]
        t = h5f['events/t']
        return t[0] + t_offset, t[-1] + t_offset

in preprocessing.py:

def compute_index(detection_index, discrete_timestamps):    
    mapping = np.zeros_like(discrete_timestamps, dtype="uint64")
    for i, t in enumerate(discrete_timestamps):
        mapping[i] = np.searchsorted(detection_index, t, side='right') - 1 
        mapping[i] = max(mapping[i], 0)
        mapping[i] = min(mapping[i], len(detection_index) - 1) 
    return mapping

Again the code might be wrong, be careful when you do the testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants