濟(jì)寧網(wǎng)站建設(shè)關(guān)鍵字是什么意思
VScode報錯:Segmentation fault (core dumped)的解決辦法
解決Program received signal SIGSEGV, Segmentation fault.的辛酸
Linux環(huán)境下段錯誤的產(chǎn)生原因及調(diào)試方法小結(jié)
Linux下的段錯誤Segmentationfault產(chǎn)生的原因及調(diào)試方法經(jīng)典.pdf
在程序中,TF_SessionRun
這部分總是報錯Segmentation fault
即出現(xiàn)段錯誤。現(xiàn)整理一下前后的解決過程。
首先,網(wǎng)上查找資料可知“段錯誤”一般由于訪問空的指針或者堆棧溢出等。因此首先判斷TF_SessionRun
各參數(shù)中是否存在空指針。
使用下面這段代碼可以判斷指針是否為空,
if (int_tensor != NULL) {printf("----------------TF_NewTensor is OK----------------\n");} elseprintf("ERROR: Failed TF_NewTensor\n");InputValues[0] = int_tensor;if (Input != NULL) {printf("----------------TF_Input is OK----------------\n");} else {printf("ERROR: Failed TF_Input\n");}if (InputValues != NULL) {printf("----------------TF_InputValues is OK----------------\n");} else {printf("ERROR: Failed TF_InputValues\n");}if (Output != NULL) {printf("----------------TF_Output is OK----------------\n");} else {printf("ERROR: Failed TF_Output\n");}if (OutputValues != NULL) {printf("----------------TF_OutputValues is OK----------------\n");} else {printf("ERROR: Failed TF_OutputValues\n");}if (TF_GetCode(Status) == TF_OK) {printf("----------------Status is OK----------------\n");} else {printf("%s", TF_Message(Status));}if (Session != NULL) {printf("----------------Session is OK----------------\n");} else {printf("ERROR: Failed Session\n");}
程序運(yùn)行后顯示沒有問題,
那么考慮第二種可能,會不會是TF_SessionRun
中的某些元素初始化沒有成功?通過對比兩篇文章的代碼,我們發(fā)現(xiàn)在構(gòu)建input
和output
時出現(xiàn)了問題,因此需要加上兩行代碼即可:
//構(gòu)建Input、Output
Input[0] = t_input;
Output[0] = t_output;
解決辦法: