Skip to content

DLFW changes #2552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions examples/int8/training/vgg16/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
import torch.nn.functional as F
import torch.optim as optim
import torch.utils.data as data
import torchvision.transforms as transforms
import torchvision.datasets as datasets

from torch.utils.tensorboard import SummaryWriter

import torchvision.transforms as transforms
from vgg16 import vgg16

PARSER = argparse.ArgumentParser(
Expand Down Expand Up @@ -64,7 +61,6 @@

timestamp = datetime.timestamp(now)

writer = SummaryWriter(args.tensorboard + "/test_" + str(timestamp))
classes = (
"plane",
"car",
Expand All @@ -82,7 +78,6 @@
def main():
global state
global classes
global writer
if not os.path.isdir(args.ckpt_dir):
os.makedirs(args.ckpt_dir)

Expand Down Expand Up @@ -131,9 +126,6 @@ def main():
data = iter(training_dataloader)
images, _ = next(data)

writer.add_graph(model, images.cuda())
writer.close()

crit = nn.CrossEntropyLoss()
opt = optim.SGD(
model.parameters(),
Expand All @@ -156,8 +148,6 @@ def main():

for epoch in range(args.start_from, args.epochs):
adjust_lr(opt, epoch)
writer.add_scalar("Learning Rate", state["lr"], epoch)
writer.close()
print("Epoch: [%5d / %5d] LR: %f" % (epoch + 1, args.epochs, state["lr"]))

train(model, training_dataloader, crit, opt, epoch)
Expand All @@ -179,7 +169,6 @@ def main():


def train(model, dataloader, crit, opt, epoch):
global writer
model.train()
running_loss = 0.0
for batch, (data, labels) in enumerate(dataloader):
Expand All @@ -192,10 +181,6 @@ def train(model, dataloader, crit, opt, epoch):

running_loss += loss.item()
if batch % 50 == 49:
writer.add_scalar(
"Training Loss", running_loss / 100, epoch * len(dataloader) + batch
)
writer.close()
print(
"Batch: [%5d | %5d] loss: %.3f"
% (batch + 1, len(dataloader), running_loss / 100)
Expand All @@ -204,7 +189,6 @@ def train(model, dataloader, crit, opt, epoch):


def test(model, dataloader, crit, epoch):
global writer
global classes
total = 0
correct = 0
Expand All @@ -223,12 +207,6 @@ def test(model, dataloader, crit, epoch):
total += labels.size(0)
correct += (preds == labels).sum().item()

writer.add_scalar("Testing Loss", loss / total, epoch)
writer.close()

writer.add_scalar("Testing Accuracy", correct / total * 100, epoch)
writer.close()

test_probs = torch.cat([torch.stack(batch) for batch in class_probs])
test_preds = torch.cat(class_preds)
for i in range(len(classes)):
Expand Down Expand Up @@ -263,14 +241,6 @@ def add_pr_curve_tensorboard(class_index, test_probs, test_preds, global_step=0)
tensorboard_preds = test_preds == class_index
tensorboard_probs = test_probs[:, class_index]

writer.add_pr_curve(
classes[class_index],
tensorboard_preds,
tensorboard_probs,
global_step=global_step,
)
writer.close()


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion notebooks/EfficientNet-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@
"# The compiled module will have precision as specified by \"op_precision\".\n",
"# Here, it will have FP32 precision.\n",
"trt_model_fp32 = torch_tensorrt.compile(model, inputs = [torch_tensorrt.Input((128, 3, 224, 224), dtype=torch.float32)],\n",
" enabled_precisions = torch.float32, # Run with FP32\n",
" enabled_precisions = {torch.float32}, # Run with FP32\n",
" workspace_size = 1 << 22\n",
")"
]
Expand Down