def test_feature_decoder(self): # Make random feature. feat_size = 64 feat = np.random.randn(feat_size).astype(np.float32) label = np.zeros(1).astype(np.int64) # Encode feat_example = dataset_to_records.make_example([ ('image/embedding', 'float32', feat), ('image/class/label', 'int64', [label]), ]) # Decode feat_decoder = decoder.FeatureDecoder(feat_len=feat_size) feat_decoded = feat_decoder(feat_example) # Assert perfect reconstruction. with self.session(use_gpu=False) as sess: feat_rec_numpy = sess.run(feat_decoded) self.assertAllEqual(feat_rec_numpy, feat)
def test_feature_decoder(self): # Make random feature. feat_size = 64 feat = np.random.randn(feat_size).astype(np.float32) label = np.zeros(1).astype(np.int64) with self.session(use_gpu=False) as sess: feat_serial = sess.run(tf.io.serialize_tensor(feat)) # Encode feat_example = dataset_to_records.make_example( feat_serial, label, input_key='image/embedding', label_key='image/class/label') # Decode feat_decoder = decoder.FeatureDecoder() feat_decoded = feat_decoder(feat_example) # Assert perfect reconstruction. with self.session(use_gpu=False) as sess: feat_rec_numpy = sess.run(feat_decoded) self.assertAllEqual(feat_rec_numpy, feat)