Skip to content

Commit

Permalink
Adding composite transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
eldakms committed May 13, 2016
1 parent b73c3cc commit a197259
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
32 changes: 14 additions & 18 deletions Source/Readers/ImageReader/ImageReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
#include "ImageReader.h"
#include "Config.h"
#include "ImageConfigHelper.h"
#include "ImageTransformers.h"
#include "BlockRandomizer.h"
#include "NoRandomizer.h"
#include "ImageDataDeserializer.h"
#include "FramePacker.h"
#include "CompositeTransformer.h"
#include <omp.h>
#include "ImageSlimTransformers.h"

namespace Microsoft { namespace MSR { namespace CNTK {

Expand Down Expand Up @@ -53,29 +54,24 @@ ImageReader::ImageReader(MemoryProviderPtr provider,

randomizer->Initialize(nullptr, config);

auto cropper = std::make_shared<CropTransformer>();
cropper->Initialize(randomizer, config);
size_t featureStreamId = configHelper.GetFeatureStreamId();
ConfigParameters featureStream = config(m_streams[featureStreamId]->m_name);

auto scaler = std::make_shared<ScaleTransformer>();
scaler->Initialize(cropper, config);
// Create transformations.
std::vector<Transformation> transformations;
transformations.push_back(Transformation{ std::make_shared<SlimCropTransformer>(featureStream), featureStreamId });
transformations.push_back(Transformation{ std::make_shared<SlimScaleTransformer>(featureStream), featureStreamId });
transformations.push_back(Transformation{ std::make_shared<SlimColorTransformer>(featureStream), featureStreamId });
transformations.push_back(Transformation{ std::make_shared<SlimIntensityTransformer>(featureStream), featureStreamId });
transformations.push_back(Transformation{ std::make_shared<SlimMeanTransformer>(featureStream), featureStreamId });

auto color = std::make_shared<ColorTransformer>();
color->Initialize(scaler, config);

auto intensity = std::make_shared<IntensityTransformer>();
intensity->Initialize(color, config);

auto mean = std::make_shared<MeanTransformer>();
mean->Initialize(intensity, config);

TransformerPtr last = mean;
if (configHelper.GetDataFormat() == CHW)
{
last = std::make_shared<TransposeTransformer>();
last->Initialize(mean, config);
transformations.push_back(Transformation{ std::make_shared<SlimTransposeTransformer>(featureStream), featureStreamId });
}

m_transformer = last;
m_transformer = std::make_shared<CompositeTransformer>(transformations);
m_transformer->Initialize(randomizer, config);

m_packer = std::make_shared<FramePacker>(
m_provider,
Expand Down
2 changes: 1 addition & 1 deletion Source/Readers/ImageReader/ImageSlimTransformers.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class SlimMeanTransformer : public SlimImageTransformerBase
};

// Transpose transformation from HWC to CHW.
class SlimTransposeTransformer : public SlimTransformerPtr
class SlimTransposeTransformer : public SlimTransformer
{
public:
explicit SlimTransposeTransformer(const ConfigParameters& config);
Expand Down
2 changes: 1 addition & 1 deletion Source/Readers/ReaderLib/CompositeTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CompositeTransformer : public Transformer
m_chainOfStreamDescriptions.push_back(streams);
for (auto& t : m_transformations)
{
streams[t.m_streamId] = t.m_transfromer->Transform(*streams[t.m_streamId]);
streams[t.m_streamId] = std::make_shared<StreamDescription>(t.m_transfromer->Transform(*streams[t.m_streamId]));
m_chainOfStreamDescriptions.push_back(streams);
}
}
Expand Down

0 comments on commit a197259

Please sign in to comment.