!学习使我快乐! 2021-08-11 14:20 采纳率: 0%
浏览 117
已结题

代码加上plt.imshow(resized_image)就会报错:段错误 (核心已转储) ?

def preprocess_image(image_file):
    resized_image = Image.open(image_file).resize((224, 224))
    #plt.imshow(resized_image) #对图像进行处理,并显示其格式
    plt.show() #将plt.imshow()处理后的函数显示出来
    image_data = np.asarray(resized_image).astype("float32")
    # convert HWC to CHW
    #image_data = image_data.transpose((2, 0, 1))
    # after expand_dims, we have format NCHW
    image_data = np.expand_dims(image_data, axis=0)
    image_data[:, 0, :, :] = 2.0 / 255.0 * image_data[:, 0, :, :] - 1
    image_data[:, 1, :, :] = 2.0 / 255.0 * image_data[:, 1, :, :] - 1
    image_data[:, 2, :, :] = 2.0 / 255.0 * image_data[:, 2, :, :] - 1
    print("input", image_data.shape)
    return image_data

注释掉 plt.imshow(resized_image) 代码运行正常
加上就出现错误:段错误 (核心已转储)

  • 写回答

1条回答 默认 最新

  • !学习使我快乐! 2021-08-11 14:32
    关注
    Thread debugging using libthread_db enabled]
    
    Thread 1 "python" received signal SIGSEGV, Segmentation fault.
    PyModule_GetState ()
        at /tmp/build/80754af9/python_1627392990942/work/Objects/moduleobject.c:565
    565    /tmp/build/80754af9/python_1627392990942/work/Objects/moduleobject.c: 没有那个文件或目录.
    (gdb) where
    #0  PyModule_GetState ()
        at /tmp/build/80754af9/python_1627392990942/work/Objects/moduleobject.c:565
    #1  0x00007fff3b30dc44 in on_startup_hook ()
        at /usr/local/src/conda/python-3.7.11/Modules/readline.c:900
    #2  0x00007fff36a4a3e1 in rl_initialize ()
       from /usr/lib/x86_64-linux-gnu/libedit.so.2
    #3  0x00007fff3b30de3d in setup_readline.isra.0 ()
        at /usr/local/src/conda/python-3.7.11/Modules/readline.c:1156
    #4  PyInit_readline ()
        at /usr/local/src/conda/python-3.7.11/Modules/readline.c:1372
    #5  0x000055555577ec6c in _PyImport_LoadDynamicModuleWithSpec ()
        at /tmp/build/80754af9/python_1627392990942/work/Python/importdl.c:159
    #6  0x000055555577ee73 in _imp_create_dynamic_impl.isra.15 (file=0x0, 
        spec=0x7ffeeb2db290)
        at /tmp/build/80754af9/python_1627392990942/work/Python/import.c:2174
    #7  _imp_create_dynamic ()
        at /tmp/build/80754af9/python_1627392990942/work/Python/clinic/import.c.h:289
    #8  0x000055555569d772 in _PyMethodDef_RawFastCallDict ()
        at /tmp/build/80754af9/python_1627392990942/work/Objects/call.c:530
    #9  0x000055555571c30b in _PyCFunction_FastCallDict (kwargs=0x7ffeeb2d7370, 
        nargs=<optimized out>, args=0x7ffeeb2db1e8, func=0x7ffff69f87d0)
        at /tmp/build/80754af9/python_1627392990942/work/Objects/call.c:585
    ---Type <return> to continue, or q <return> to quit---quit
    Quit
    
    
    
    评论

报告相同问题?

问题事件

  • 系统已结题 8月19日
  • 创建了问题 8月11日

悬赏问题

  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题