Skip to content

Comments

HDF5_DATA + MEMORY_DATA refuse loudly to transform#1841

Merged
shelhamer merged 1 commit intoBVLC:devfrom
shelhamer:no-memory-or-hdf5-transform
Feb 10, 2015
Merged

HDF5_DATA + MEMORY_DATA refuse loudly to transform#1841
shelhamer merged 1 commit intoBVLC:devfrom
shelhamer:no-memory-or-hdf5-transform

Conversation

@shelhamer
Copy link
Member

These layers are meant for generic inputs so they do not do transformations. As transform_param was pulled out of data layers' proto definitions for reuse, these layers silently ignored transformation parameters until now instead of signalling their refusal.

Transforming could be added in a future PR. Better to make sure users know the current state first.

See #1718.

These layers are meant for generic inputs so they do not do
transformations. As `transform_param` was pulled out of data layers'
proto definitions for reuse, these layers silently ignored
transformation parameters until now instead of signalling their refusal.
@shelhamer shelhamer force-pushed the no-memory-or-hdf5-transform branch from fcccc2a to 56846e6 Compare February 7, 2015 07:18
@shelhamer shelhamer changed the title HDF5_DATA + MEMORY_DATA refuse loudly to transform -- fix #1718 HDF5_DATA + MEMORY_DATA refuse loudly to transform Feb 7, 2015
@DmitryUlyanov
Copy link
Contributor

I can create PR with transforms for memory_data, do you need that ?

shelhamer added a commit that referenced this pull request Feb 10, 2015
HDF5_DATA + MEMORY_DATA refuse loudly to transform
@shelhamer shelhamer merged commit 5e61f55 into BVLC:dev Feb 10, 2015
@shelhamer
Copy link
Member Author

@DmitryUlyanov if extending MemoryDataLayer::Reset() to transform is useful to you then you could send a PR -- however we've always thought of this data layer as taking input arrays exactly as they are. Note that it does transform when adding vectors of Datum or cv::Mat as-is.

@longjon thoughts?

@DmitryUlyanov
Copy link
Contributor

@shelhamer well, I don't actually think It's a good way to transform things when doing reset (or Add...Vector) because during training you obviously want to have some random transformations every time. So I did it in Forward_cpu and didn't feel net started to work any slower on my 40x40 images with batch_size = 300, I did it like that (this version is outdated a bit):

void MemoryDataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
      const vector<Blob<Dtype>*>& top) {
  CHECK(data_) << "MemoryDataLayer needs to be initalized by calling Reset";

  if (this->layer_param_.has_transform_param()) {

    // Copy to blob
    Blob<Dtype> b;
    b.Reshape(batch_size_, channels_, height_, width_);
    b.set_cpu_data(data_ + pos_ * size_);

    // transform
    this->data_transformer_.Transform(&b, top[0]);

    // Copy labels
    top[1]->set_cpu_data(labels_ + pos_);

    } else {
    top[0]->set_cpu_data(data_ + pos_ * size_);
    top[1]->set_cpu_data(labels_ + pos_);
  }
  pos_ = (pos_ + batch_size_) % n_;
  has_new_data_ = false;
}

And anyway user can omit transform_params in config so memory_data will take input arrays exactly as they are with no overhead at all.
So if this way is satisfactory I will send a PR.

@rohitgirdhar
Copy link

Even with MemoryDataLayer, I use the prototxt to specify what transform parameters to use (in AddMatVector function). However the check added in this PR fails, and the program aborts. Is there another way to add DataTransfomer parameters through the code? (whatever examples I've seen take it from the prototxt file).

@shelhamer
Copy link
Member Author

This check was accidentally too stringent for MemoryDataLayer. @DmitryUlyanov your approach is better, so please send a PR for transforming memory data as outlined.

(While transforming during forward isn't ideal it's the best solution at present.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants