juglab / n2v

This is the implementation of Noise2Void training.
Other
385 stars 107 forks source link

make N2V_DataGenerator extensible to more file formats #134

Closed thawn closed 1 year ago

thawn commented 1 year ago

by supplying imread as a callable parameter to N2V_DataGenerator.load_images, it is easier to support different file formats.

For example, if I wanted to use nikon nd2 files instead of tiff, I would write the following imread function:

import numpy as np
from aicsimageio import AICSImage

def imread(file_path):
    image = AICSImage(file_path)
    return image.data.astype(np.float32)

I could then call the data generator like this and it would automagically work for nd2 files instead of tiffs:

from n2v.internals.N2V_DataGenerator import N2V_DataGenerator
from pathlib import Path

data_dir = Path("/path/to/data")
datagen = N2V_DataGenerator()
files = sorted(data_dir.glob("*.nd2"))
image_list = datagen.load_imgs(files, image_reader=imread)
...
thawn commented 1 year ago

running pytest tests/test_Noise2VoidDataGenerator.py did not return any errors.

running pytest returned errors complaining about missing json files:

ERROR tests/functional/test_prediction2D_RGB.py - FileNotFoundError: config file doesn't exist: n2v/models/n2v_2D_RGB/config.json
ERROR tests/functional/test_prediction2D_SEM.py - FileNotFoundError: config file doesn't exist: n2v/models/n2v_2D_SEM/config.json
ERROR tests/functional/test_prediction3D.py - FileNotFoundError: config file doesn't exist: n2v/models/n2v_3D/config.json