ptyhonではじめて画像分類のプログラムを以下のサイトを参考に書きました。
<Deep Learningで犬・猫を分類してみよう-ai_academy-https://aiacademy.jp/texts/show/?id=164>
認識できるクラスが無ければ新たにクラスを追加し、もう一度学習を行うことができるように変えてみました。
しかし、この場合もう一度学習を行う際も一度目の学習と同じようにかなりの時間がかかります。追加したクラスだけを学習させ、学習時間の短縮を行うことは可能でしょうか。ご教授いただければ幸いです。
python
from h5py._hl.files import File import numpy as np from keras.models import load_model from PIL import Image from matplotlib import pyplot as plt import pickle from icrawler.builtin import BingImageCrawler import shutil imsize = (64, 64) with open('classes',mode='rb')as f: classes=pickle.load(f) while True: imagess=input('画像を入力してください>>') testpic= imagess keras_param = "./cnn.h5" def load_image(path): img = Image.open(path) img = img.convert('RGB') img = img.resize(imsize) # 画像データをnumpy配列の形式に変更 img = np.asarray(img) img = img / 255.0 return img model = load_model(keras_param) img = load_image(testpic) prd = model.predict(np.array([img])) print(prd) # 精度の表示 prelabel = np.argmax(prd, axis=1) print(classes) answer=input('この中に該当のクラスはありますかy/n>>') if answer== "y" : for f in range(len(classes)): if prelabel == f: print(classes[f]) answer2=input("正解ですかy/n>>") if answer2=="y": print("ok") elif answer2=="n": print(classes) k=input('該当のクラスを指定してください>>') shutil.copy(imagess, './images/'+k) elif answer=="n": name = input("新たなクラスを入力して下さい>>") crawler = BingImageCrawler(storage={"root_dir": name}) crawler.crawl(keyword=name, max_num=100) new_path = shutil.move(name, 'images/'+name) import dateset import train
Layer
Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= conv2d (Conv2D) (None, 64, 64, 32) 896 activation (Activation) (None, 64, 64, 32) 0 conv2d_1 (Conv2D) (None, 62, 62, 32) 9248 activation_1 (Activation) (None, 62, 62, 32) 0 max_pooling2d (MaxPooling2D (None, 31, 31, 32) 0 ) dropout (Dropout) (None, 31, 31, 32) 0 conv2d_2 (Conv2D) (None, 31, 31, 64) 18496 activation_2 (Activation) (None, 31, 31, 64) 0 conv2d_3 (Conv2D) (None, 29, 29, 64) 36928 activation_3 (Activation) (None, 29, 29, 64) 0 max_pooling2d_1 (MaxPooling (None, 14, 14, 64) 0 2D) dropout_1 (Dropout) (None, 14, 14, 64) 0 dense (Dense) (None, 512) 6423040 activation_4 (Activation) (None, 512) 0 dropout_2 (Dropout) (None, 512) 0 dense_1 (Dense) (None, 3) 1539 activation_5 (Activation) (None, 3) 0 ================================================================= Total params: 6,490,147 Trainable params: 6,490,147 Non-trainable params: 0
まだ回答がついていません
会員登録して回答してみよう