글 작성자: 만렙개발자

 

from tqdm import tqdm
	for images, targets, image_ids in tqdm(holdout_loader, total=len(holdout_loader)):

 

위의 코드처럼 tqdm loop을 만들어서 돌리면 아래와 같이 무식하게 출력된다.

 

 

이 문제를 해결하는 법은 매우 단순하다. tqdm은 이미 ipython jupyter를 위해 개발이 되어있다.

tqdm을 tqdm.tqdm 대신에 tqdm.atuo.tqdm 혹은 tqdm.notebook.tqdm을 사용하면 된다.

 

from tqdm.auto import tqdm

그러면 아래와 같이 깔끔해진다.

 

의외로 print를 많이하면 속도가 많이 느려지기 때문에, (그리고 끝없이 쌓이면 메모리가 터져버릴 때도 있습니다.)

이쁘게 보이는 것만을 위해서가 아니라, 꼭 쓰셔야 합니다!

 

다른 코드 없이 단순히 예제를 돌리고 싶다면 아래의 코드를 사용하시면 됩니다.

 

from tqdm.auto import tqdm, trange
from time import sleep

for i in trange(10, desc='1st loop'):
    for j in tqdm(xrange(100), desc='2nd loop'):
        sleep(0.01)

 

reference: https://github.com/tqdm/tqdm/#ipython-jupyter-integration