VITA-Group / EnlightenGAN

[IEEE TIP] "EnlightenGAN: Deep Light Enhancement without Paired Supervision" by Yifan Jiang, Xinyu Gong, Ding Liu, Yu Cheng, Chen Fang, Xiaohui Shen, Jianchao Yang, Pan Zhou, Zhangyang Wang
Other
890 stars 198 forks source link

ImportError: cannot import name lib #60

Closed ojasviyadav closed 3 years ago

ojasviyadav commented 4 years ago

I'm running Python 3.5. I have also installed all the packages in requirement.txt. I'm getting this error:

Traceback (most recent call last):
  File "train.py", line 19, in <module>
    model = create_model(opt)
  File "/home/EnlightenGAN/models/models.py", line 20, in create_model
    from .single_model import SingleModel
  File "/home/EnlightenGAN/models/single_model.py", line 15, in <module>
    from . import networks
  File "/home/EnlightenGAN/models/networks.py", line 11, in <module>
    from lib.nn import SynchronizedBatchNorm2d as SynBN2d
ImportError: No module named lib.nn

I tried to google this error and this repository had 2 issues that are now closed which were similar to this one. In those it was mentioned to install Python3.5 and make sure requirement.txt was fulfilled. I have tried that.

The only difference I had was that I did not start the visdom server because I'm training this on a remote machine using the terminal. But I am not sure if that is causing this issue?

ghost commented 3 years ago

If you're running the script.py to train, make sure to change "python train.py" to "python3 train.py". I guess I had this issue before and this fixed it.

xzhub commented 3 years ago

I have to do this:

cp -r lib/nn models/

then vi models/networks.py to change the line to:

from .nn import SynchronizedBatchNorm2d as SynBN2d
xzhub commented 3 years ago

However, when I run this command:

python scripts/script.py --predict

I saw these errors:

Total number of parameters: 8636675
-----------------------------------------------
model [SingleGANModel] was created
No handlers could be found for logger "visdom"
Exception in user code:
------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/visdom/__init__.py", line 711, in _send
    data=json.dumps(msg),
  File "/usr/local/lib/python2.7/site-packages/visdom/__init__.py", line 677, in _handle_post
    r = self.session.post(url, data=data)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 572, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f091bea73d0>: Failed to establish a new connection: [Errno 111] Connection refused',))
24
Traceback (most recent call last):
  File "predict.py", line 25, in <module>
    for i, data in enumerate(dataset):
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
    data.reraise()
  File "/usr/local/lib64/python2.7/site-packages/torch/_utils.py", line 394, in reraise
    raise self.exc_type(msg)
ZeroDivisionError: Caught ZeroDivisionError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/tmp/gan/EnlightenGAN/data/unaligned_dataset.py", line 82, in __getitem__
    B_img = self.B_imgs[index % self.B_size]
ZeroDivisionError: integer division or modulo by zero
yifanjiang19 commented 3 years ago

You should firstly run python -m visdom.server to launch a port to receive visual results. Then make sure your dataset path is correct. From the above error message, the dataset length is zero which might be caused by wrong dataset path.

ojasviyadav commented 3 years ago

If you're running the script.py to train, make sure to change "python train.py" to "python3 train.py". I guess I had this issue before and this fixed it.

This is not working for me

ojasviyadav commented 3 years ago

However, when I run this command:

python scripts/script.py --predict

I saw these errors:

Total number of parameters: 8636675
-----------------------------------------------
model [SingleGANModel] was created
No handlers could be found for logger "visdom"
Exception in user code:
------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/visdom/__init__.py", line 711, in _send
    data=json.dumps(msg),
  File "/usr/local/lib/python2.7/site-packages/visdom/__init__.py", line 677, in _handle_post
    r = self.session.post(url, data=data)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 572, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f091bea73d0>: Failed to establish a new connection: [Errno 111] Connection refused',))
24
Traceback (most recent call last):
  File "predict.py", line 25, in <module>
    for i, data in enumerate(dataset):
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
    data.reraise()
  File "/usr/local/lib64/python2.7/site-packages/torch/_utils.py", line 394, in reraise
    raise self.exc_type(msg)
ZeroDivisionError: Caught ZeroDivisionError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/tmp/gan/EnlightenGAN/data/unaligned_dataset.py", line 82, in __getitem__
    B_img = self.B_imgs[index % self.B_size]
ZeroDivisionError: integer division or modulo by zero

I fixed the original error. But just like you, I am also getting this error

yifanjiang19 commented 3 years ago

@ojasviyadav Could you please check whether your dataset path is correct?

zhangziyezzy commented 3 years ago

However, when I run this command:

python scripts/script.py --predict

I saw these errors:

Total number of parameters: 8636675
-----------------------------------------------
model [SingleGANModel] was created
No handlers could be found for logger "visdom"
Exception in user code:
------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/visdom/__init__.py", line 711, in _send
    data=json.dumps(msg),
  File "/usr/local/lib/python2.7/site-packages/visdom/__init__.py", line 677, in _handle_post
    r = self.session.post(url, data=data)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 572, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f091bea73d0>: Failed to establish a new connection: [Errno 111] Connection refused',))
24
Traceback (most recent call last):
  File "predict.py", line 25, in <module>
    for i, data in enumerate(dataset):
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
    data.reraise()
  File "/usr/local/lib64/python2.7/site-packages/torch/_utils.py", line 394, in reraise
    raise self.exc_type(msg)
ZeroDivisionError: Caught ZeroDivisionError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib64/python2.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/tmp/gan/EnlightenGAN/data/unaligned_dataset.py", line 82, in __getitem__
    B_img = self.B_imgs[index % self.B_size]
ZeroDivisionError: integer division or modulo by zero

I also met the same error. Have you solve this problem?

yifanjiang19 commented 3 years ago

@zhangziyezzy Could you please try to print self.B_size?

zhangziyezzy commented 3 years ago

I have recreated a new env and also installed all the packages in requirement.txt. when I just run the test code "python scripts/script.py --predict", it's ok, just like this:

Total number of parameters: 8636675 model [SingleGANModel] was created Setting up a new session... 3 process image... ['../test_dataset/testA/P1000511.jpg'] process image... ['../test_dataset/testA/P1000333.jpg'] process image... ['../test_dataset/testA/P1000205.jpg']

But I could not find where is the output saved

yifanjiang19 commented 3 years ago

It should be in the results

yifanjiang19 commented 3 years ago

@xzhub @zhangziyezzy The error is because of no data placed in testB. You should put your input images in testA and at least put one image in testB.

zhangziyezzy commented 3 years ago

OK, I find the results of "fake” images in ./ablationfolder.