Closed jpainam closed 2 years ago
@jpainam this seems like it might be expected behavior - if you try to register any component a second time, we raise an error.
If you think you are not re-registering a parameter scheduler, can you share details about your environment and the code you ran?
I donāt think itās necessary to raise an error when someone tries to register a component for a second. A simple warning might be enough. I only register my custom dataset once. And the error seems to occur during the optimizer and scheduler build. I'm using Jupyter notebook and all the cells run except the cell where i defined my scheduler and optimizer.
I agree that the error raising isn't great for most use cases - it was written to prevent a different set of scenarios. It's especially frustrating when working on Jupyter notebooks. I'm sorry for the inconvenience, we'll keep this in mind for future fixes.
I'm hoping you are able to make progress on the tutorial though after restarting your kernel?
I executed this code using a .py file and a Jupyter notebook with a fresh kernel. Restarted it many times. same error,
from classy_vision.tasks import ClassificationTask
from classy_vision.optim import build_optimizer
from classy_vision.losses import build_loss
from classy_vision.meters import build_meters, AccuracyMeter, VideoAccuracyMeter
from classy_vision.heads import build_head
from collections import defaultdict
from classy_vision.models import build_model
loss = build_loss({"name": "CrossEntropyLoss"})
optimizer = build_optimizer({
"name": "sgd",
"param_schedulers": {
"lr": {
"name": "multistep",
"values": [0.005, 0.0005],
"milestones": [1]
}
},
"num_epochs": 25,
"weight_decay": 0.0001,
"momentum": 0.9
})
meters = build_meters({
"accuracy": {
"topk": [1, 5]
},
"video_accuracy": {
"topk": [1, 5],
"clips_per_video_train": 1,
"clips_per_video_test": 10
}
})
unique_id = "default_head"
head = build_head({
"name": "fully_convolutional_linear",
"unique_id": unique_id,
"pool_size": [1, 7, 7],
"num_classes": 2,
"in_plane": 512
})
model = build_model({
"name": "resnext3d",
"frames_per_clip": 8, # The number of frames we have in each video clip
"input_planes": 3, # We use RGB video frames. So the input planes is 3
"clip_crop_size": 112, # We take croppings of size 112 x 112 from the video frames
"skip_transformation_type": "postactivated_shortcut", # The type of skip connection in residual unit
"residual_transformation_type": "basic_transformation", # The type of residual connection in residual unit
"num_blocks": [2, 2, 2, 2], # The number of residual blocks in each of the 4 stages
"input_key": "video", # The key used to index into the model input of dict type
"stage_planes": 64,
"num_classes": 2 # the number of classes
})
# In Classy Vision, the head can be attached to any residual block in the trunk.
# Here we attach the head to the last block as in the standard ResNet model
fork_block = "pathway0-stage4-block1"
heads = {fork_block: [head]}
model.set_heads(heads)
num_epochs = 25
task = (
ClassificationTask()
.set_num_epochs(num_epochs)
.set_loss(loss)
.set_model(model)
.set_optimizer(optimizer)
.set_meters(meters)
)
#for phase in ["train", "test"]:
# task.set_dataset(datasets[phase], phase)
Hope the code is self-contained and can be executed. This is my environment
python 3.6
classy_vision 0.5.0
torch 1.8
torchvision 0.9.0
I was not able to repro the error - upon copying the code with the same environment as you mentioned @jpainam I was able to run the code without any issues. Maybe try creating a new environment from scratch and trying this out?
These are the steps I followed -
conda create --name classy_762 python=3.6
conda activate classy_762
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch
pip install classy_vision==0.5.0
vim test_classy_762.py
python test_classy_762.py
š Bug
I'm reproducing the video classification. In the 4 step, Building the task. i get this error