Skip to content

02_hw_fmnist_classification.ipynb: Error on attempt to parse model #130

@iworeushankaonce

Description

@iworeushankaonce

When running the last cell with

# do not change the code in the block below
# __________start of block__________
assert os.path.exists(
    "hw_fmnist_data_dict.npy"
), "Please, download `hw_fmnist_data_dict.npy` and place it in the working directory"

loaded_data_dict = np.load("hw_fmnist_data_dict.npy", allow_pickle=True)

submission_dict = {
    "train_predictions_task_1": get_predictions(
        model_task_1, torch.FloatTensor(loaded_data_dict.item()["train"])
    ),
    "test_predictions_task_1": get_predictions(
        model_task_1, torch.FloatTensor(loaded_data_dict.item()["test"])
    ),
    "model_task_1": parse_pytorch_model(str(model_task_1)),
}

with open("submission_dict_fmnist_task_1.json", "w") as iofile:
    json.dump(submission_dict, iofile)
print("File saved to `submission_dict_fmnist_task_1.json`")
# __________end of block__________

the following error pops up, if CNN architecture was used as a model

Traceback (most recent call last):

  File c:\Users\gabdu\anaconda3\envs\torch\lib\site-packages\IPython\core\interactiveshell.py:3577 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  Cell In[33], line 16
    "model_task_1": parse_pytorch_model(str(model_task_1)),

  Cell In[32], line 33 in parse_pytorch_model
    model_dict["layers"].append({"index": int(index), "layer": parse_layer(layer)})

  Cell In[32], line 15 in parse_layer
    param_dict[key.strip()] = eval(value.strip())

  File <string>:1
    (3
    ^
SyntaxError: '(' was never closed

The issue seems to be persistent and is reported by other students as well.

Not to share my partial solution, I am not providing my exact architecture but for the purpose of debugging can share privately to course instructors. If this error was intended, please ignore this issue.

OS: Windows 11
Torch version: 2.5.1+cu124

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions