当前位置:   article > 正文

SyntaxError: positional argument follows keyword argument

syntaxerror: positional argument follows keyword argument

问题原因

出现这个问题,是因为在传参的过程中将位置参数放到了不合适的问题。具体为什么是这个原因,可能与Python读取参数的顺序有关

具体在运行改写deep-image-prior网络时的代码 。

刚开始调用时采用下面的代码出现这个错误

// A code block
#调用
self.plot_image_save([outputs], factor=5,fake_image_path)
  • 1
  • 2
  • 3

接着更改为下面的调用方式不再进行报错

// A code block
#调用
self.plot_image_save([outputs], fake_image_path,factor=5)
  • 1
  • 2
  • 3
// An highlighted block
    def plot_image_save(self,images_np,factor=1):
        nrow = 8
        interpolation = 'lanczos'
        n_channels = max(x.shape[0] for x in images_np)
        assert (n_channels == 3) or (n_channels == 1),

        images_np = [x if (x.shape[0] == n_channels) else np.concatenate([x, x, x], axis=0) for x in images_np]

        grid = get_image_grid(images_np, nrow)

        plt.figure(figsize=(len(images_np) + factor, 12 + factor))

        if images_np[0].shape[0] == 1:
            plt.imshow(grid[0], cmap='gray', interpolation=interpolation)
        else:
            plt.imshow(grid.transpose(1, 2, 0), interpolation=interpolation)

        plt.rcParams['savefig.dpi'] = 256  # 图片像素
        plt.rcParams['figure.dpi'] = 256  # 分辨率
        plt.axis('off')
        plt.savefig(pathxxx, bbox_inches='tight', dpi=256, pad_inches=0.0)
        return grid

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/903031
推荐阅读
  

闽ICP备14008679号