In C1M2_Assignment where are the mean and std calculated from as they don't match my calculations

in this assignment there is hardcoded
mean = (0.1736,)
std = (0.3317,)

however the following code shows slightly different values – how did you arrive at these hardcoded values?

train_dataset_raw = torchvision.datasets.EMNIST(root=data_path, split=‘letters’,train=True, download=False)
train_images = train_dataset_raw.data.float() / 255.0
mean1 = round(train_images.mean().item(), 4)std1 = round(train_images.std(unbiased=True,).item(), 4)
print(f"Mean: {mean1}, Std: {std1}")

They compute the mean and std separately. They compute it after using the same method of loading the data that they show in this assignment, which used torch.ToTensor. That scales the data to be between 0 and 1, but perhaps their method is different than just dividing by 255.

Here’s another recent thread that shows a way to compute the mean and std for MNIST in a way that gives the same numbers they showed in that assignment. You could port that code to the EMNIST case and see if you get different numbers than you did with your method.

1 Like

I have a problem in EMNIST Letter-Detective. Everything was going fine till I recahed the training phase. There is an issue with the following line.

trained_model, _ = train_epoch(model, train_loader, loss_function, optimizer, device, verbose=True)
It says Type Error: 'Adam' object is not iterable. I am stuck here. Can you help?

You must be invoking the optimizer incorrectly. One way that could happen is using square brackets instead of parens. In python, if I reference an object like this:

myObject[value]

it means a completely different thing than if I write it this way:

myObject(value)

In the first case, that means that myObject is “iterable” in python, e.g. a list or an array, and you are using value as an index to select a subset of that object.

In the second case with parens, that means myObject is a function and you are calling it and passing value as the first parameter.

It might help to show us the full exception trace that you are getting. Not the actual source code, please.

Also note that you have added this reply to a thread that has nothing to do with your question other than the fact that it is also about the EMNIST assignment (C1 M2). In general, it’s better to create a new thread for a new topic and place it in the right category, but I realize that if you are a new user, they don’t give you the trust level to create a new thread until you’ve done a few things on the forum. Also the UI actions to create a new thread are more complicated and not as clear. :nerd_face: Soon you’ll have the power to create your own new threads. Just something to keep in mind.

I fixed it. It’s just I passed the arguments in the wrong order. Thank you.

1 Like