Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw Net Problem (%d format: a number is required) #3201

Closed
FreakTheMighty opened this issue Oct 15, 2015 · 3 comments
Closed

Draw Net Problem (%d format: a number is required) #3201

FreakTheMighty opened this issue Oct 15, 2015 · 3 comments

Comments

@FreakTheMighty
Copy link

This seem similar to #1709. In the master branch, when running ./python/draw_net.py, I get this traceback. Seems like this is an area that regresses frequently, what would a good test look like to prevent this from happening again?

root@0e28b3340f95:/opt/caffe# python ./python/draw_net.py ./foo.proto /data/net.png
libdc1394 error: Failed to initialize libdc1394
Couldn't import dot_parser, loading of dot files will not be possible.
Drawing net to /data/net.png
Traceback (most recent call last):
  File "./python/draw_net.py", line 45, in <module>
    main()
  File "./python/draw_net.py", line 41, in main
    caffe.draw.draw_net_to_file(net, args.output_image_file, args.rankdir)
  File "/opt/caffe/python/caffe/draw.py", line 213, in draw_net_to_file
    fid.write(draw_net(caffe_net, rankdir, ext))
  File "/opt/caffe/python/caffe/draw.py", line 195, in draw_net
    return get_pydot_graph(caffe_net, rankdir).create(format=ext)
  File "/opt/caffe/python/caffe/draw.py", line 142, in get_pydot_graph
    node_label = get_layer_label(layer, rankdir)
  File "/opt/caffe/python/caffe/draw.py", line 89, in get_layer_label
    layer.convolution_param.pad)
TypeError: %d format: a number is required, not RepeatedScalarFieldContainer
@FreakTheMighty FreakTheMighty changed the title Draw Net Problem Draw Net Problem (%d format: a number is required) Oct 15, 2015
@erogol
Copy link
Contributor

erogol commented Oct 16, 2015

change the corresponding function as following in python/caffe/draw.py

def get_layer_label(layer, rankdir):
    """Define node label based on layer type.

    Parameters
    ----------
    layer : ?
    rankdir : {'LR', 'TB', 'BT'}
        Direction of graph layout.

    Returns
    -------
    string :
        A label for the current layer
    """

    if rankdir in ('TB', 'BT'):
        # If graph orientation is vertical, horizontal space is free and
        # vertical space is not; separate words with spaces
        separator = ' '
    else:
        # If graph orientation is horizontal, vertical space is free and
        # horizontal space is not; separate words with newlines
        separator = '\\n'

    if layer.type == 'Convolution' or layer.type == 'Deconvolution':
        # Outer double quotes needed or else colon characters don't parse
        # properly
        param = layer.convolution_param
        node_label = '"%s%s(%s)%skernel size: %d%sstride: %d%spad: %d"' %\
                    (layer.name,
                     separator,
                     layer.type,
                     separator,
                     layer.convolution_param.kernel_size[0] if len(layer.convolution_param.kernel_size._values) else 1,
                     separator,
                     layer.convolution_param.stride[0] if len(layer.convolution_param.stride._values) else 1,
                     separator,
                     layer.convolution_param.pad[0] if len(layer.convolution_param.pad._values) else 0)
    elif layer.type == 'Pooling':
        pooling_types_dict = get_pooling_types_dict()
        node_label = '"%s%s(%s %s)%skernel size: %d%sstride: %d%spad: %d"' %\
                     (layer.name,
                      separator,
                      pooling_types_dict[layer.pooling_param.pool],
                      layer.type,
                      separator,
                      layer.pooling_param.kernel_size,
                      separator,
                      layer.pooling_param.stride,
                      separator,
                      layer.pooling_param.pad)
    else:
        node_label = '"%s%s(%s)"' % (layer.name, separator, layer.type)
    return node_label

@shelhamer
Copy link
Member

Seems like this is an area that regresses frequently, what would a good test look like to prevent this from happening again?

A minimal but helpful improvement would be to add a Python test that imports caffe.draw and calls draw_net() to check that it at least runs without exception. That could be a good PR to encourage further testing.

@ngaloppo
Copy link
Contributor

I have a similar problem for the Pooling layer type. I fixed and published #5010.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants