def checkpoint_save(epoch: int, nn_model: model, nn_optimizer: torch.optim, training_loss: list, validation_loss: list, model_name: str, locations: dict, args): """ Save model checkpoints """ checkpoint_name = model_name.replace('.tar','_chkepo_{0}.tar'.format(str(epoch).zfill(3))) torch.save({'epoch':epoch, 'model_state_dict':nn_model.state_dict(), 'optimizer_state_dict':nn_optimizer.state_dict(), 'training_loss':training_loss, 'validation_loss':validation_loss, 'arguments':args}, locations['model_loc']+'/'+checkpoint_name)
# one_hot_labels[i][train_label[i]] = 1 # train_labels_1hot = one_hot_labels # train_labels_1hot.shape # load data print("Loading data .................") # train_image = load_data(train_image_path) test_image = load_data(test_image_path) label_name = ['city', 'forest', 'sea'] print("Starting test image .......................................") # Lấy dữ liệu đã train lên để test VGG13 = Model() VGG13.load_weights('trained_model_1v.hdf5') def test(index): # predict() sử dụng mô hình để dự đoán ảnh đầu vào. # predict() hoạt động ntn ???????????????????====================================================== predict = VGG13.predict(test_image[index].reshape((1,HEIGHT,WIDTH,DEEP))) plt.imshow(test_image[index]) print("Du doan nhan cua anh:") print(predict) if np.argmax(predict) == 0: print('I am sure this is city') plt.show() elif np.argmax(predict) == 1: print('I am sure this is forest')