Skip to content

Instantly share code, notes, and snippets.

View rafalpronko's full-sized avatar

Rafal Pronko rafalpronko

View GitHub Profile
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)
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))
model_load_py = torch.load("/content/drive/My Drive/article/model.pt")
model_load_py
torch.save(modelpy, "/content/drive/My Drive/article/model.pt")
test_loss, test_acc = modeltf.evaluate(test_images_tf, test_labels_tf)
print('Test accuracy:', test_acc)
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]))
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))
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)
%%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)
modeltf.compile(optimizer=keras.optimizers.Adam(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
modeltf.summary()