Open gvalvano opened 2 years ago
This seems like image loading failed and mmcv.imfrombytes
with cv2
backend returns a NoneType
.
Please make sure all images under your folder are valid.
Hello @LeoXing1996 and thank you for the support. It seems you may be right, after removing some images raising python warnings from the dataset I can train the model without obtaining the previous error anymore.
I have created a small snippet to detect problematic files, which I leave below, in case someone may find it useful :) let me know if you think it is worth including a bash-runnable version of this code in MMGeneration, I would be happy to create a pull request.
from pathlib import Path
import warnings
# use this to catch warnings
warnings.filterwarnings("error")
paths = glob.glob(str(Path(source_folder) / "*.jpg"))
paths.sort()
n_images = len(paths)
skipped = 0
for k, path in enumerate(paths):
print(f"\nFile: {path}")
try:
x = PIL.Image.open(path)
x = np.asarray(x, dtype="uint8")
assert len(x.shape) == 3 # [w, h, c]
assert x.shape[-1] == 3 # RGB, 3 channels
del x
except:
print(f" |--> Invalid file, moving into: {dest_folder}")
shutil.move(path, dest_folder)
skipped += 1
This is a quite useful script for user-defined datasets and you are welcome to create a PR about this.
However, I suggest this checking operation should be based on the config file. Because whether an image is valid or not is related to its loading pipeline. For example, we may allow images with single-channel (grayscale image) or 4 channels (RGBA) in some config.
One more thing, you may run the following command to install the pre-commit hooks before committing:
pre-commit install
Good idea :) I'll be happy to do so. How can I check how many channels should the input have from the config file?
Maybe we can directly build the loading pipeline from the config.
@LeoXing1996 Has this issue been supported in PRs? Please consider to help @gvalvano to complete related PRs.
Describe the bug The training starts correctly, but it suddenly stops with
AttributeError
after a while.Reproduction
The config file:
../data/images_collection/
Environment
python mmgen/utils/collect_env.py
to collect necessary environment information and paste it here.$PATH
,$LD_LIBRARY_PATH
,$PYTHONPATH
, etc.) --> N.AError traceback If applicable, paste the error trackback here.
Bug fix If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!