2016-08-22 7 views
0

次のコードセグメントを実行すると、plt.imshow(X[0,:,:]) plt.show()の最後の2行にエラーメッセージIllegal instruction (core dumped)が生成され続けます。これの理由は何か分かりますか?numpyとmatplotlibを使用して生成されたイメージを表示するときに不正な命令(コアダンプ)メッセージ

import os 
import numpy as np 
import matplotlib.pyplot as plt 
import pylab 
from scipy.ndimage.filters import gaussian_filter 
from scipy import ndimage 

np.random.seed(1234) 
pylab.rcParams['figure.figsize'] = (10.0, 8.0) 

nx = 572 
ny = 572 
sigma = 10 

plateau_min = -2 
plateau_max = 2 

r_min = 1 
r_max = 200 

def create_image_and_label(nx,ny): 
    x = np.int(np.random.rand(1)[0]*nx) 
    y = np.int(np.random.rand(1)[0]*ny) 

    image = np.ones((nx,ny)) 
    label = np.ones((nx,ny)) 
    image[x,y] = 0 
    image_distance = ndimage.morphology.distance_transform_edt(image) 

    r = np.random.rand(1)[0]*(r_max-r_min)+r_min 
    plateau = np.random.rand(1)[0]*(plateau_max-plateau_min)+plateau_min 

    label[image_distance <= r] = 0 
    label[image_distance > r] = 1 
    label = (1 - label) 

    image_distance[image_distance <= r] = 0 
    image_distance[image_distance > r] = 1 
    image_distance = (1 - image_distance)*plateau 

    image = image_distance + np.random.randn(nx,ny)/sigma 

    return image, label[92:nx-92,92:nx-92] 

def create_batch(nx,ny,n_image): 

    X = np.zeros((n_image,nx,ny)) 
    Y = np.zeros((n_image,nx-184,ny-184,2)) 

    for i in range(n_image): 
    X[i,:,:],Y[i,:,:,1] = create_image_and_label(nx,ny) 
    Y[i,:,:,0] = 1-Y[i,:,:,1] 

    return X,Y 

X,Y = create_batch(nx,ny,1) 

print(X.shape) 
plt.imshow(X[0,:,:]) 
plt.show() 
+0

これはmatplotlibのバグのようです。メーリングリスト(http://matplotlib.org/faq/troubleshooting_faq.html)にレポートを提出することを検討しましたか? – nneonneo

+0

これは、通常、誰かがファイルにテキストエディタを使用した場合、または間違ったアーキテクチャである場合、 "壊れた"バイナリ.soファイルによって引き起こされる可能性があります。 – cdarke

+0

この問題に関連する可能性があります:https://bbs.archlinux.org/viewtopic.php?id=215589同じエラーが発生したときの解決法(atlas-lapack-baseをアンインストールしてlapackをインストールする)が私にとってうまくいった。 – Mark

答えて

0

私にとってはうまく動作します。ライブラリやPythonのアップグレードや再インストールをお試しください。

まだ失敗する場合は、gdbを使用してスタックトレースを取得することを検討してください(ヒント:gdb /path/to/your/python)。その後、@nneonneoの示唆どおりにbug reportをmatplotlibに提出してください。

+0

上記のお返事ありがとうございます。私はPythonの仮想環境の下でプログラムを実行しています。私はこの環境を終了して再入力するだけです。そして、今働いています。これについての可能なヒント。 – user297850

+0

ポインタのバグがあり、メモリが壊れている拡張モジュールを使用していますか?このような状況の通常の結果はコアダンプです。問題を再現できる場合、最良の解決策は、 'gdb'を使ってコアダンプを解析するか、' gdb'の下でPythonを実行して、失敗した時点でスタックトレースを取得することです。別のアプローチは 'valgrind'を使ってポインタバグをキャッチしようとすることです。 –

関連する問題