# Property setter for Dataset

**URL:** <https://discuss.pytorch.org/t/property-setter-for-dataset/32103>\
**Category:** Uncategorized\
**Created:** [December 14, 2018, 4:00am UTC](https://discuss.pytorch.org/t/property-setter-for-dataset/32103 "2018-12-14T04:00:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pswarup](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/pswarup/32/6786_2.png) [@pswarup](https://discuss.pytorch.org/u/pswarup)\
**Post date:** [December 14, 2018, 4:00am UTC](https://discuss.pytorch.org/t/property-setter-for-dataset/32103/1 "2018-12-14T04:00:49Z")

</div>

I am trying to change a property of my Dataset. However the value is not updated when using workers. What do I need to do to allow dynamic update of variables when using workers to load data via DataLoader?

Example:

ImageDataset(torch.utils.data.Dataset):  
\_variance = 1.0

```
@property
def i(self):
    return type(self)._variance

@i.setter
def i(self, val):
    type(self)._variance = val

```

From the training loop:  
ImageDataset.\_variance = 0.5

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [December 14, 2018, 12:05pm UTC](https://discuss.pytorch.org/t/property-setter-for-dataset/32103/2 "2018-12-14T12:05:08Z")

</div>

Do you need to update your `Dataset`during an epoch or would it be sufficient to update it after each one?  
In the latter case, have a look at [this example](https://discuss.pytorch.org/t/solved-will-change-in-dataset-be-reflected-on-dataloader-automatically/10206/2?u=ptrblck).

---

<div class="post-metadata">

**Author:** ![pswarup](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/pswarup/32/6786_2.png) [@pswarup](https://discuss.pytorch.org/u/pswarup)\
**Post date:** [December 18, 2018, 10:17am UTC](https://discuss.pytorch.org/t/property-setter-for-dataset/32103/3 "2018-12-18T10:17:26Z")

</div>

I would like to update the parameters for each mini-batch, parameter update after each epoch doesn’t solve my issue.

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [December 18, 2018, 12:04pm UTC](https://discuss.pytorch.org/t/property-setter-for-dataset/32103/4 "2018-12-18T12:04:44Z")

</div>

Could this be implemented in the ` __getitem__ ` using some logic or do you need to pass the new value from outside?  
In the latter case, you could try to adapt this [shared arrays approach](https://discuss.pytorch.org/t/dataloader-resets-dataset-state/27960/4?u=ptrblck).

---

<div class="post-metadata">

**Author:** ![pswarup](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/pswarup/32/6786_2.png) [@pswarup](https://discuss.pytorch.org/u/pswarup)\
**Post date:** [December 19, 2018, 7:09am UTC](https://discuss.pytorch.org/t/property-setter-for-dataset/32103/5 "2018-12-19T07:09:38Z")

</div>

Yes I need to update this from the training loop i.e. outside, the shared arrays approach looks good.
