Skip to content

IndexError: During training 0-dim tensor error #117

@divyanshujhawar

Description

@divyanshujhawar

While executing the train.py file,

IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>() in C++ to convert a 0-dim tensor to a number

The complete log has been attached below:

D_adam_b1: 0.5
D_adam_b2: 0.999
G_adam_b1: 0.5
G_adam_b2: 0.999
aus_file: aus_openface.pkl
batch_size: 4
checkpoints_dir: ./checkpoints
cond_nc: 17
data_dir: GANimation-master/sample_dataset1
dataset_mode: aus
display_freq_s: 300
do_saturate_mask: False
gpu_ids: [0]
image_size: 128
images_folder: imgs
is_train: True
lambda_D_cond: 4000
lambda_D_gp: 10
lambda_D_prob: 1
lambda_cyc: 10
lambda_mask: 0.1
lambda_mask_smooth: 1e-05
load_epoch: 0
lr_D: 0.0001
lr_G: 0.0001
model: ganimation
n_threads_test: 1
n_threads_train: 4
name: experiment_1
nepochs_decay: 10
nepochs_no_decay: 20
num_iters_validate: 1
poses_g_sigma: 0.06
print_freq_s: 60
save_latest_freq_s: 3600
serial_batches: False
test_ids_file: test_ids.csv
train_G_every_n_iterations: 5
train_ids_file: train_ids.csv
-------------- End ----------------
./checkpoints/experiment_1
Dataset AusDataset was created
Dataset AusDataset was created
#train images = 15
#test images = 15
Network generator_wasserstein_gan was created
Network discriminator_wasserstein_gan was created
Model GANimation was created
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/content/GANimation-master/train.py in <module>()
    139 
    140 if __name__ == "__main__":
--> 141     Train()

4 frames
/content/GANimation-master/models/ganimation.py in get_current_errors(self)
    318         loss_dict = OrderedDict([('g_fake', self._loss_g_fake.data[0]),
    319                                  ('g_cond', self._loss_g_cond.data[0]),
--> 320                                  ('g_mskd_fake', self._loss_g_masked_fake.data[0]),
    321                                  ('g_mskd_cond', self._loss_g_masked_cond.data[0]),
    322                                  ('g_cyc', self._loss_g_cyc.data[0]),

IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>() in C++ to convert a 0-dim tensor to a number


I have run all the previous commands, including the requirements.txt file. While looking for this over the net, I found that it is due to the update in the Pytorch version which does not allow accessing the last element as [0], we need to use .item(). But, even after changing it, I am getting the same error.

Anyone facing the same issues?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions