def predict_image(model, file_path): _, pred = forward(model, load_image(file_path), empty_label(), train=False) print '多分これかな?: %s' % (pred.data)
# init optimizer optimizer = optimizers.Adam() optimizer.setup(model) # load data data = [] walk_dir(args.data_dir, lambda i, f: data.extend([(num_to_label(i), load_image(f))])) # learn for i in range(args.epoch): random.shuffle(data) t = 0 pbar = ProgressBar(len(data)) for (label, img) in data: optimizer.zero_grads() loss, acc = forward(model, img, label, train=True) loss.backward() optimizer.update() t += 1 pbar.update(t) print '%s 回繰り返し学習を行った' % (i + 1) print 'ヨッシャ! 学習おわったでw' # dump model pickle.dump(model, open('AlexNet_epoch_%s.pickle' % (args.epoch), 'wb'), -1)