https://qiita.com/slowsingle/items/64cc927bb29a49a7af14←こちらのコードを使用しました
http://ai-coordinator.jp/ssd-keras-train
https://qiita.com/slowsingle/items/9006383145a650c84cb0
こちらの記事を参考にして同じことをやっているのですが、途中で学習が止まってしまい、次のエポックへ移行しません。
こちらがterminalの出力です。最後の7/8から進みません。
python
1 2/Users/anaconda3/envs/tf/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py:95: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory. 3 "Converting sparse IndexedSlices to a dense Tensor of unknown shape. " 4Epoch 1/2 57/8 [=========================>....] - ETA: 21s - loss: 6.7430 6
python
1import cv2 2import keras 3from keras.applications.imagenet_utils import preprocess_input 4from keras.backend.tensorflow_backend import set_session 5from keras.models import Model 6from keras.preprocessing import image 7import matplotlib.pyplot as plt 8import numpy as np 9import pickle 10from random import shuffle 11from scipy.misc import imread 12from scipy.misc import imresize 13import tensorflow as tf 14 15from ssd import SSD300 16from ssd_training import MultiboxLoss 17from ssd_utils import BBoxUtility 18 19plt.rcParams['figure.figsize'] = (8, 8) 20plt.rcParams['image.interpolation'] = 'nearest' 21 22np.set_printoptions(suppress=True) 23 24# 21 25NUM_CLASSES = 21 #4 26input_shape = (300, 300, 3) 27 28priors = pickle.load(open('prior_boxes_ssd300.pkl', 'rb')) 29bbox_util = BBoxUtility(NUM_CLASSES, priors) 30 31# gt = pickle.load(open('gt_pascal.pkl', 'rb')) 32gt = pickle.load(open('VOC2007.pkl', 'rb')) 33keys = sorted(gt.keys()) 34num_train = int(round(0.8 * len(keys))) 35train_keys = keys[:num_train] 36val_keys = keys[num_train:] 37num_val = len(val_keys) 38 39##teratailの文字数制限のため省略、省略箇所を確認したい場合はお手数ですが連絡をください 40 41nb_epoch = 2 42history = model.fit_generator(gen.generate(True), gen.train_batches, 43 nb_epoch, verbose=1, 44 callbacks=callbacks, 45 validation_data=gen.generate(False), 46 nb_val_samples=gen.val_batches, 47 nb_worker=1) 48 49inputs = [] 50images = [] 51img_path = path_prefix + sorted(val_keys)[0] 52img = image.load_img(img_path, target_size=(300, 300)) 53img = image.img_to_array(img) 54images.append(imread(img_path)) 55inputs.append(img.copy()) 56inputs = preprocess_input(np.array(inputs)) 57 58preds = model.predict(inputs, batch_size=1, verbose=1) 59results = bbox_util.detection_out(preds) 60 61for i, img in enumerate(images): 62 # Parse the outputs. 63 det_label = results[i][:, 0] 64 det_conf = results[i][:, 1] 65 det_xmin = results[i][:, 2] 66 det_ymin = results[i][:, 3] 67 det_xmax = results[i][:, 4] 68 det_ymax = results[i][:, 5] 69 70 # Get detections with confidence higher than 0.6. 71 top_indices = [i for i, conf in enumerate(det_conf) if conf >= 0.6] 72 73 top_conf = det_conf[top_indices] 74 top_label_indices = det_label[top_indices].tolist() 75 top_xmin = det_xmin[top_indices] 76 top_ymin = det_ymin[top_indices] 77 top_xmax = det_xmax[top_indices] 78 top_ymax = det_ymax[top_indices] 79 80 colors = plt.cm.hsv(np.linspace(0, 1, NUM_CLASSES)).tolist() 81 82 plt.imshow(img / 255.) 83 currentAxis = plt.gca() 84 85 for i in range(top_conf.shape[0]): 86 xmin = int(round(top_xmin[i] * img.shape[1])) 87 ymin = int(round(top_ymin[i] * img.shape[0])) 88 xmax = int(round(top_xmax[i] * img.shape[1])) 89 ymax = int(round(top_ymax[i] * img.shape[0])) 90 score = top_conf[i] 91 label = int(top_label_indices[i]) 92 # label_name = voc_classes[label - 1] 93 display_txt = '{:0.2f}, {}'.format(score, label) 94 coords = (xmin, ymin), xmax-xmin+1, ymax-ymin+1 95 color = colors[label] 96 currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor=color, linewidth=2)) 97 currentAxis.text(xmin, ymin, display_txt, bbox={'facecolor':color, 'alpha':0.5}) 98 99 plt.show()
あなたの回答
tips
プレビュー