raghakot / keras-vis

Neural network visualization toolkit for keras
https://raghakot.github.io/keras-vis
MIT License
2.98k stars 664 forks source link

error font searching... in utils.py #44

Closed nicezic closed 7 years ago

nicezic commented 7 years ago

I got a font related error running the first sample code.

My env is , no GPU, Win10, conda with python 3.6

What I did first was downloading and install 'FreeSan.ttf' into system.

However, it didn't help out.

Then, I figured out what the problem was.

For me, this code, "len(font_files)" in vis/util/utils.py causes the problem.

#    font_files = _find_font_file(font)
#     if len(font_files) == 0:
#         logger.warn("Failed to lookup font '{}', falling back to default".format(font))
#         font = ImageFont.load_default()
#     else:
#         font = ImageFont.truetype(font_files[0], font_size)
    font = ImageFont.load_default()

So, This is my way around, just using default font without checking a specific font.

FYI, Below is the traceback.

Model loaded. Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/User/Documents/tf/untitled4.py', wdir='C:/Users/User/Documents/tf')

File "C:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile execfile(filename, namespace)

File "C:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/User/Documents/tf/untitled4.py", line 32, in opt.minimize(max_iter=500, verbose=True, image_modifiers=[Jitter()], callbacks=[GifGenerator('opt_progress')])

File "C:\Anaconda3\lib\site-packages\vis\optimizer.py", line 134, in minimize c.callback(i, named_losses, overall_loss, grads, wrt_value)

File "C:\Anaconda3\lib\site-packages\vis\callbacks.py", line 61, in callback img = utils.draw_text(img, "Step {}".format(i + 1))

File "C:\Anaconda3\lib\site-packages\vis\utils\utils.py", line 232, in draw_text if len(font_files) == 0:

TypeError: object of type 'filter' has no len()

raghakot commented 7 years ago

Are you using install from source? This was an old issue that happens because of python2/3 inconsistency and has been fixed. Feel free ti reopen if you see this in latest.

Lijiachen1018 commented 6 years ago

I am using Win10, Python 3.5 I still got the problem, no FreeSans.ttf ,so i use the font 'Arial.ttf' img = utils.draw_text(img, 'Filter {}'.format(idx), font='Arial.ttf')

keisen commented 6 years ago

Hi @Lijiachen1018 . Your problem was not reproduced in my test environment. (But I have no Win10, so my environment is Win7, Python3.5 (Anaconda).) Can you give me error log?

Lijiachen1018 commented 6 years ago

It is because no FreeSan.ttf file in my system so I tried 'Arial.ttf' or 'Times.ttf' The error: Failed to lookup font 'FreeSans.ttf', falling back to default