This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modeltf.save('modeltf.h5') | |
model_load_tf = tf.keras.models.load_model('modeltf.h5') | |
model_load_tf.summary() | |
test_loss, test_acc = model_load_tf.evaluate(test_images_tf, test_labels_tf) | |
print('Test accuracy:', test_acc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
correct = 0 | |
total = 0 | |
for images, labels in test_loader: | |
outputs = model_load_py(images) | |
_, predicted = torch.max(outputs.data, 1) | |
total += labels.size(0) | |
correct += (predicted == labels).sum() | |
print('Test Accuracy of the model on the {} test images: {}%'.format(total, 100 * correct / total)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_load_py = torch.load("/content/drive/My Drive/article/model.pt") | |
model_load_py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
torch.save(modelpy, "/content/drive/My Drive/article/model.pt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_loss, test_acc = modeltf.evaluate(test_images_tf, test_labels_tf) | |
print('Test accuracy:', test_acc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_images_tf = test_images_tf.reshape(test_images_tf.shape[0], | |
test_images_tf.shape[1], | |
test_images_tf.shape[2], 1) | |
predictions = modeltf.predict(test_images_tf) | |
correct = 0 | |
for i, pred in enumerate(predictions): | |
if np.argmax(pred) == test_labels_tf[i]: | |
correct += 1 | |
print('Test Accuracy of the model on the {} test images: {}%'.format(test_images_tf.shape[0], | |
100 * correct/test_images_tf.shape[0])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
correct = 0 | |
total = 0 | |
modelpy.eval() | |
for images, labels in test_loader: | |
outputs = modelpy(images) | |
_, predicted = torch.max(outputs.data, 1) | |
total += labels.size(0) | |
correct += (predicted == labels).sum() | |
print('Test Accuracy of the model on the {} test images: {}%'.format(total, 100 * correct / total)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_images_tf = train_images_tf.reshape(train_images_tf.shape[0], | |
train_images_tf.shape[1], | |
train_images_tf.shape[2], 1) | |
%%time | |
modeltf.fit(train_images_tf, train_labels_tf, epochs=10, batch_size=32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
for e in range(10): | |
# define the loss value after the epoch | |
losss = 0.0 | |
number_of_sub_epoch = 0 | |
# loop for every training batch (one epoch) | |
for images, labels in train_loader: | |
#create the output from the network | |
out = modelpy(images) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modeltf.compile(optimizer=keras.optimizers.Adam(), | |
loss='sparse_categorical_crossentropy', | |
metrics=['accuracy']) | |
modeltf.summary() |
NewerOlder