機械学習初心者です.JypyterでTensorflow(keras)を用いCNNを構成し,fittingのコードを実行させたタイミングでカーネルが異常終了してしまいます.
今回はjupyterでは結果の出力枠にWarningなど表示せず,ウィンドウにて以下メッセージを表示してお亡くなりになります.
カーネルは再起動中です カーネルが異常終了した様です。自動的に再起動します。
これだけだと原因は分からなかったので,スクリプトにおこして実行すると,今度は次のエラーが出ます
2021-01-01 16:20:37.030154: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations: SSE4.1 SSE4.2 AVX AVX2 AVX512F FMA To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags. 2021-01-01 16:20:37.030423: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 8. Tune using inter_op_parallelism_threads for best performance. Train on 22967 samples, validate on 5742 samples Epoch 1/50 python(14456,0x7000076fc000) malloc: Incorrect checksum for freed object 0x7fed99d3d868: probably modified after being freed. Corrupt value: 0x10400076fa040 python(14456,0x7000076fc000) malloc: *** set a breakpoint in malloc_error_break to debug zsh: abort python test.py
mallocなどを調べてみたのですが解決策にはいたらず...
コードは以下になります.
Python
1 2import numpy as np 3import pandas as pd 4import matplotlib.pyplot as plt 5%matplotlib inline 6import matplotlib.image as mpimg 7 8import tensorflow as tf 9from tensorflow import keras 10from sklearn.model_selection import train_test_split 11 12import os 13os.environ['KMP_DUPLICATE_LIB_OK']='TRUE' 14 15 16label_map = ['Anger', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral'] 17names_train=['emotion','pixels'] 18names_test=['pixels'] 19df_test=pd.read_csv('./hoge/test.csv',names=names_test, na_filter=False) 20df_test=df_test.drop([0],axis=0) 21df_train=pd.read_csv('./hoge/train.csv',names=names_train, na_filter=False) 22df_train=df_train.drop([0],axis=0) 23 24 25def gray_to_rgb(im): 26 w, h = im.shape 27 ret = np.empty((w, h, 3), dtype=np.uint8) 28 ret[:, :, 2] = ret[:, :, 1] = ret[:, :, 0] = im 29 return ret 30 31def convert_to_image(pixels, mode="save", t="gray"): 32 if type(pixels) == str: 33 pixels = np.array([int(i) for i in pixels.split()]) 34 if mode == "show": 35 if t == "gray": 36 return pixels.reshape(48,48) 37 else: 38 return gray_to_rgb(pixels.reshape(48,48)) 39 else: 40 return pixels 41 42 43df_train["pixels"] = df_train["pixels"].apply(lambda x : convert_to_image(x, mode="show", t="gray")) 44df_test["pixels"] = df_test["pixels"].apply(lambda x : convert_to_image(x, mode="show", t="gray")) 45 46 47X_train, X_val, y_train, y_val = train_test_split(df_train["pixels"], df_train["emotion"], test_size=0.2, random_state=1) 48 49X_train = np.array(list(X_train[:]), dtype=np.float) 50X_val = np.array(list(X_val[:]), dtype=np.float) 51 52y_train = np.array(list(y_train[:]), dtype=np.float) 53y_val = np.array(list(y_val[:]), dtype=np.float) 54 55X_train = X_train.reshape(X_train.shape[0], 48, 48, 1) 56X_val = X_val.reshape(X_val.shape[0], 48, 48, 1) 57 58 59X_test=np.array(list(df_test['pixels']), dtype=np.float) 60 61 62X_test = X_test.reshape(X_test.shape[0], 48, 48, 1) 63 64IMG_SIZE=48 65 66model = keras.models.Sequential([ 67 keras.layers.Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(IMG_SIZE,IMG_SIZE,1)), 68 keras.layers.BatchNormalization(axis=1), 69 keras.layers.MaxPooling2D(pool_size=(2, 2)), 70 71 keras.layers.Conv2D(64, kernel_size=(3, 3), activation='relu'), 72 keras.layers.BatchNormalization(axis=1), 73 keras.layers.MaxPooling2D(pool_size=(2, 2)), 74 75 keras.layers.Conv2D(64, kernel_size=(3, 3), activation='relu'), 76 keras.layers.BatchNormalization(axis=1), 77 keras.layers.MaxPooling2D(pool_size=(2, 2)), 78 79 keras.layers.Conv2D(32, kernel_size=(3, 3), activation='relu'), 80 keras.layers.BatchNormalization(axis=1), 81 keras.layers.MaxPooling2D(pool_size=(2, 2)), 82 83 keras.layers.Flatten(), 84 keras.layers.Dense(512, activation='relu'), 85 keras.layers.Dropout(0.2), 86 keras.layers.Dense(512, activation='relu'), 87 keras.layers.Dropout(0.2), 88 keras.layers.Dense(7, activation='softmax') 89]) 90 91model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) 92 93model.fit(X_train,y_train,epochs=50,batch_size=64,validation_data=(X_val,y_val))
初歩的な質問で申し訳ありませんが,よろしくお願いいたします.
回答1件
あなたの回答
tips
プレビュー