本文整理汇总了Python中tensorflow.compat.v2.string方法的典型用法代码示例。如果您正苦于以下问题:Python v2.string方法的具体用法?Python v2.string怎么用?Python v2.string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.compat.v2
的用法示例。
在下文中一共展示了v2.string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict(
{
"speech": tfds.features.Audio(),
"text": tfds.features.Text(
encoder_config=self.builder_config.text_encoder_config
),
"speaker_id": tf.int64,
"chapter_id": tf.int64,
"id": tf.string,
"label": tfds.features.ClassLabel(names=_LABELS),
}
),
supervised_keys=("speech", "label"),
homepage=_URL,
citation=_CITATION,
metadata=tfds.core.MetadataDict(sample_rate=16000,),
)
示例2: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict({
"data":
collections.OrderedDict([
("marketplace", tf.string), ("customer_id", tf.string),
("review_id", tf.string), ("product_id", tf.string),
("product_parent", tf.string), ("product_title", tf.string),
("product_category", tf.string), ("star_rating", tf.int32),
("helpful_votes", tf.int32), ("total_votes", tf.int32),
("vine", tfds.features.ClassLabel(names=["Y", "N"])),
("verified_purchase",
tfds.features.ClassLabel(names=["Y", "N"])),
("review_headline", tf.string), ("review_body", tf.string),
("review_date", tf.string)
])
}),
supervised_keys=None,
homepage="https://s3.amazonaws.com/amazon-reviews-pds/readme.html",
citation=_CITATION,
)
示例3: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict({
'book_text': tfds.features.Text(),
'book_id': tf.int32,
'book_title': tf.string,
'publication_date': tf.string,
'book_link': tf.string
}),
supervised_keys=None,
homepage='https://github.com/deepmind/pg19',
citation=_CITATION,
)
示例4: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _info(self) -> tfds.core.DatasetInfo:
config = self.builder_config
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict({
config.name_key:
tf.string,
config.id_key:
tf.string,
config.summary_key:
tf.string,
config.opinions_key:
tfds.features.Sequence(
tfds.features.FeaturesDict({
"key": tf.string,
"value": tf.string
})),
}),
supervised_keys=(config.opinions_key, config.summary_key),
homepage="http://www.ccs.neu.edu/home/luwang/data.html",
citation=_CITATION,
)
示例5: _parse_single_image
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _parse_single_image(self, example_proto):
"""Parses single video from the input tfrecords.
Args:
example_proto: tfExample proto with a single video.
Returns:
dict with all frames, positions and actions.
"""
feature_map = {
"image": tf.io.FixedLenFeature(shape=[], dtype=tf.string),
"filename": tf.io.FixedLenFeature(shape=[], dtype=tf.string),
"label": tf.io.FixedLenFeature(shape=[], dtype=tf.int64),
}
parse_single = tf.io.parse_single_example(example_proto, feature_map)
return parse_single
示例6: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict({
"speech":
tfds.features.Audio(sample_rate=16000),
"text":
tfds.features.Text(
encoder_config=self.builder_config.text_encoder_config),
"speaker_id":
tf.int64,
"chapter_id":
tf.int64,
"id":
tf.string,
}),
supervised_keys=("speech", "text"),
homepage=_URL,
citation=_CITATION,
metadata=tfds.core.MetadataDict(sample_rate=16000,),
)
示例7: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=self.builder_config.description,
features=tfds.features.FeaturesDict({
"speech":
tfds.features.Audio(sample_rate=16000),
"text":
tfds.features.Text(),
"speaker_id":
tf.string,
"gender":
tfds.features.ClassLabel(names=["unknown", "female", "male"]),
"id":
tf.string,
}),
supervised_keys=("speech", "text"),
homepage=self.builder_config.url,
citation=self.builder_config.citation,
metadata=tfds.core.MetadataDict(sample_rate=16000,),
)
示例8: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _info(self):
features_dict = {
"id": tf.string,
"drummer":
tfds.features.ClassLabel(
names=["drummer%d" % i for i in range(1, 11)]),
"type": tfds.features.ClassLabel(names=["beat", "fill"]),
"bpm": tf.int32,
"time_signature": tfds.features.ClassLabel(names=_TIME_SIGNATURES),
"style": {
"primary": tfds.features.ClassLabel(names=_PRIMARY_STYLES),
"secondary": tf.string,
},
"midi": tf.string
}
if self.builder_config.include_audio:
features_dict["audio"] = tfds.features.Audio(
dtype=tf.float32, sample_rate=self.builder_config.audio_rate)
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict(features_dict),
homepage="https://g.co/magenta/groove-dataset",
citation=_CITATION,
)
示例9: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict({
"speech": tfds.features.Audio(
file_format="wav", sample_rate=24000),
"text_original": tfds.features.Text(),
"text_normalized": tfds.features.Text(),
"speaker_id": tf.int64,
"chapter_id": tf.int64,
"id": tf.string,
}),
supervised_keys=("text_normalized", "speech"),
homepage=_URL,
citation=_CITATION,
metadata=tfds.core.MetadataDict(sample_rate=24000,),
)
示例10: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict({
"id":
tf.string,
"title":
tfds.features.Text(),
"context":
tfds.features.Text(),
"question":
tfds.features.Text(),
"answers":
tfds.features.Sequence({
"text": tfds.features.Text(),
"answer_start": tf.int32,
}),
}),
# No default supervised_keys (as we have to pass both question
# and context as input).
supervised_keys=None,
homepage="https://rajpurkar.github.io/SQuAD-explorer/",
citation=_CITATION,
)
示例11: placeholder_for_type
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def placeholder_for_type(context,
type_spec,
name = None):
"""Produce a Tensorflow placeholder for this type_spec.
Args:
context: a NeuralQueryContext
type_spec: a single type_spec (see tuple_dataset)
name: a name to use for the placeholder
Returns:
a Tensorflow placeholder
Raises:
ValueError, if the type_spec is invalid
"""
if type_spec == str:
return tf.compat.v1.placeholder(tf.string, shape=[None], name=name)
elif isinstance(type_spec, str) and context.is_type(type_spec):
name = name or ('%s_ph' % type_spec)
return context.placeholder(name, type_spec).tf
else:
raise ValueError('bad type spec %r' % type_spec)
示例12: testReadWriteSpecs
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def testReadWriteSpecs(self):
logdir = FLAGS.test_tmpdir
specs = {
'a': tf.TensorSpec(shape=(2, 3), dtype=tf.float32),
'b': {
'b_1': tf.TensorSpec(shape=(5,), dtype=tf.string),
'b_2': tf.TensorSpec(shape=(5, 6), dtype=tf.int32),
}
}
utils.write_specs(logdir, specs)
# Now read and verify
specs_read = utils.read_specs(logdir)
def _check_equal(sp1, sp2):
self.assertEqual(sp1, sp2)
tf.nest.map_structure(_check_equal, specs, specs_read)
示例13: test_run_eval_actor_once
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def test_run_eval_actor_once(self):
hparams = {}
hparams['max_iter'] = 1
hparams['num_episodes_per_iter'] = 5
hparams['logdir'] = os.path.join(FLAGS.test_tmpdir, 'model')
mock_problem = testing_utils.MockProblem(unroll_length=FLAGS.unroll_length)
agent = mock_problem.get_agent()
ckpt_manager = _get_ckpt_manager(hparams['logdir'], agent=agent)
ckpt_manager.save(checkpoint_number=0)
# Create a no-op gRPC server that responds to Aggregator RPCs.
server_address = 'unix:/tmp/eval_actor_test_grpc'
server = grpc.Server([server_address])
@tf.function(input_signature=[tf.TensorSpec(shape=(), dtype=tf.string)])
def eval_enqueue(_):
return []
server.bind(eval_enqueue, batched=False)
server.start()
eval_actor.run_with_aggregator(mock_problem, server_address, hparams)
示例14: __init__
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def __init__(self, state_space_size, unroll_length=1):
self._state_space_size = state_space_size
# Creates simple dynamics (T stands for transition):
# states = [0, 1, ... len(state_space_size - 1)] + [STOP]
# actions = [-1, 1]
# T(s, a) = s + a iff (s + a) is a valid state
# = STOP otherwise
self._action_space = [-1, 1]
self._current_state = None
self._env_spec = common.EnvOutput(
reward=tf.TensorSpec(shape=[unroll_length + 1], dtype=tf.float32),
done=tf.TensorSpec(shape=[unroll_length + 1], dtype=tf.bool),
observation={
'f1':
tf.TensorSpec(
shape=[unroll_length + 1, 4, 10], dtype=tf.float32),
'f2':
tf.TensorSpec(
shape=[unroll_length + 1, 7, 10, 2], dtype=tf.float32)
},
info=tf.TensorSpec(shape=[unroll_length + 1], dtype=tf.string))
示例15: testDenseFeaturesInKeras
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import string [as 别名]
def testDenseFeaturesInKeras(self):
features = {
"text": np.array(["hello world", "pair-programming"]),
}
label = np.int64([0, 1])
feature_columns = [
hub.text_embedding_column_v2("text", self.model, trainable=True),
]
input_features = dict(
text=tf.keras.layers.Input(name="text", shape=[None], dtype=tf.string))
dense_features = tf.keras.layers.DenseFeatures(feature_columns)
x = dense_features(input_features)
x = tf.keras.layers.Dense(16, activation="relu")(x)
logits = tf.keras.layers.Dense(1, activation="linear")(x)
model = tf.keras.Model(inputs=input_features, outputs=logits)
model.compile(
optimizer="rmsprop", loss="binary_crossentropy", metrics=["accuracy"])
model.fit(x=features, y=label, epochs=10)
self.assertAllEqual(model.predict(features["text"]).shape, [2, 1])