diff --git a/visualdl/logic/sdk.cc b/visualdl/logic/sdk.cc index 8a193cc6b..04944556d 100644 --- a/visualdl/logic/sdk.cc +++ b/visualdl/logic/sdk.cc @@ -403,7 +403,8 @@ void Audio::SetSample(int index, CHECK_LE(index, num_records_) << "index should be less than or equal to number of records"; - BinaryRecord brcd(GenBinaryRecordDir(step_.parent()->dir()), std::string(data.begin(),data.end())); + BinaryRecord brcd(GenBinaryRecordDir(step_.parent()->dir()), + std::string(data.begin(), data.end())); brcd.tofile(); auto entry = step_.MutableData>(index); diff --git a/visualdl/logic/sdk.h b/visualdl/logic/sdk.h index e721242af..6f3fece24 100644 --- a/visualdl/logic/sdk.h +++ b/visualdl/logic/sdk.h @@ -170,7 +170,8 @@ struct Image { void FinishSampling(); /* - * A combined interface for IndexOfSampleTaken and SetSample, simpler but might be + * A combined interface for IndexOfSampleTaken and SetSample, simpler but + * might be * low efficiency. */ void AddSample(const std::vector& shape, @@ -362,7 +363,8 @@ struct Audio { void FinishSampling(); /* - * A combined interface for IndexOfSampleTaken and SetSample, simpler but might be + * A combined interface for IndexOfSampleTaken and SetSample, simpler but + * might be * low efficiency. */ void AddSample(int sample_rate, const std::vector& data); diff --git a/visualdl/logic/sdk_test.cc b/visualdl/logic/sdk_test.cc index 0a42ff23c..eabc9b354 100644 --- a/visualdl/logic/sdk_test.cc +++ b/visualdl/logic/sdk_test.cc @@ -132,6 +132,40 @@ TEST(Image, add_sample_test) { CHECK_EQ(image2read.num_records(), num_steps); } +TEST(Image, add_sample_test) { + const auto dir = "./tmp/sdk_test.image"; + LogWriter writer__(dir, 4); + auto writer = writer__.AsMode("train"); + + auto tablet = writer.AddTablet("image0"); + components::Image image(tablet, 3, 1); + const int num_steps = 10; + + LOG(INFO) << "write images"; + image.SetCaption("this is an image"); + for (int step = 0; step < num_steps; step++) { + image.StartSampling(); + for (int i = 0; i < 7; i++) { + vector shape({5, 5, 3}); + vector data; + for (int j = 0; j < 3 * 5 * 5; j++) { + data.push_back(float(rand()) / RAND_MAX); + } + image.AddSample(shape, data); + } + image.FinishSampling(); + } + + LOG(INFO) << "read images"; + // read it + LogReader reader__(dir); + auto reader = reader__.AsMode("train"); + auto tablet2read = reader.tablet("image0"); + components::ImageReader image2read("train", tablet2read); + CHECK_EQ(image2read.caption(), "this is an image"); + CHECK_EQ(image2read.num_records(), num_steps); +} + TEST(Histogram, AddRecord) { const auto dir = "./tmp/sdk_test.histogram"; LogWriter writer__(dir, 1);