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) 代码运行正常
加上就出现错误:段错误 (核心已转储)
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