caffe-tensorflow icon indicating copy to clipboard operation
caffe-tensorflow copied to clipboard

Failed conversion of MobileNet

Open bonseyes-admin opened this issue 8 years ago • 2 comments

Hi,

Has anyone have any luck converting MobileNet type architecture? We receive this error Pull #53 has been integrated.

Traceback (most recent call last): File "convert.py", line 60, in main() File "convert.py", line 56, in main args.phase) File "convert.py", line 27, in convert transformer = TensorFlowTransformer(def_path, caffemodel_path, phase=phase) File "caffe-tensorflow\caffe-tensorflow-master\kaffe\tensorflow\transformer.py", line 221, in init self.load(def_path, data_path, phase) File "caffe-tensorflow\caffe-tensorflow-master\kaffe\tensorflow\transformer.py", line 254, in load print_stderr(self.graph) File "caffe-tensorflow\caffe-tensorflow-master\kaffe\errors.py", line 7, in print_stderr sys.stderr.write('%s\n' % msg) File "caffe-tensorflow\caffe-tensorflow-master\kaffe\graph.py", line 125, in str tuple(out_shape))) TypeError: unsupported format string passed to tuple.format

Thanks, Tim

bonseyes-admin avatar Jul 28 '17 11:07 bonseyes-admin

@bonseyes-admin #161 hi, I have fixed the bugs. These bugs are triggered by the difference of Python2 and Python3. p.s., I am using Python3.

  1. In graph.py:
def __str__(self):
       hdr = '{:<20} {:<30} {:>20} {:>20}'.format('Type', 'Name', 'Param', 'Output')
       s = [hdr, '-' * 94]
       for node in self.topologically_sorted():
           # If the node has learned parameters, display the first one's shape.
           # In case of convolutions, this corresponds to the weights.
           if node.data:#ginger
               node.data=list(node.data)#ginger
           data_shape = str(node.data[0].shape) if node.data else '--'
           out_shape = node.output_shape or '--'
           s.append('{:<20} {:<30} {:>20} {:>20}'.format(node.kind, node.name,data_shape, str(tuple(out_shape))) )#ginger
       return '\n'.join(s)
  1. In transformer.py and shapes.py, you should add list before map()
 def format(self, arg):
        '''Returns a string representation for the given value.'''
    #    return "'%s'" % arg if isinstance(arg, basestring) else str(arg)#ginger

        return "'%s'" % arg if isinstance(arg, str) else str(arg)

    def pair(self, key, value):
        '''Returns key=formatted(value).'''
        return '%s=%s' % (key, self.format(value))

    def emit(self):
        '''Emits the Python source for this node.'''
        # Format positional arguments
        args = list(map(self.format, self.args))#ginger
        # Format any keyword arguments
        if self.kwargs:
            args += [self.pair(k, v) for k, v in self.kwargs]
        # Set the node name
        args.append(self.pair('name', self.node.name))
        args = ', '.join(args)
        return '%s(%s)' % (self.op, args)

3.change all the basestring into str

  1. In transformer.py:
 def transform_source(self):
        if self.source is None:
            mapper = TensorFlowMapper(self.graph)
            chains = mapper.map()
            emitter = TensorFlowEmitter()
            self.source = emitter.emit(self.graph.name, chains)
        return self.source.encode(encoding="utf-8")#ginger

ginger0106 avatar Feb 28 '18 08:02 ginger0106

@ginger0106 Hi, I have finished converting caffe to tensorflow. But I am a little confused about conv function: conv(3,3,32,1,1,biased=False,group=32,relu=False,name='conv2_1_dw') Can you tell me how to write the conv function in network.py? Please! Thank you very much!

Ariel-JUAN avatar Jun 01 '18 06:06 Ariel-JUAN