第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Tensorflow Estimator:緩存瓶頸

Tensorflow Estimator:緩存瓶頸

有只小跳蛙 2021-06-04 10:53:11
在遵循 tensorflow 圖像分類教程時(shí),首先它會(huì)緩存每個(gè)圖像的瓶頸:定義:cache_bottlenecks())我已經(jīng)使用 tensorflow 的Estimator. 這確實(shí)簡(jiǎn)化了所有代碼。但是我想在這里緩存瓶頸功能。這是我的model_fn. 我想緩存dense層的結(jié)果,這樣我就可以對(duì)實(shí)際訓(xùn)練進(jìn)行更改,而不必每次都計(jì)算瓶頸。我怎樣才能做到這一點(diǎn)?def model_fn(features, labels, mode, params):    is_training = mode == tf.estimator.ModeKeys.TRAIN    num_classes = len(params['label_vocab'])    module = hub.Module(params['module_spec'], trainable=is_training and params['train_module'])    bottleneck_tensor = module(features['image'])    with tf.name_scope('final_retrain_ops'):        logits = tf.layers.dense(bottleneck_tensor, units=num_classes, trainable=is_training)  # save this?    def train_op_fn(loss):        optimizer = tf.train.AdamOptimizer()        return optimizer.minimize(loss, global_step=tf.train.get_global_step())    head = tf.contrib.estimator.multi_class_head(n_classes=num_classes, label_vocabulary=params['label_vocab'])    return head.create_estimator_spec(        features, mode, logits, labels, train_op_fn=train_op_fn    )
查看完整描述

2 回答

?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

TF 無(wú)法在您編碼時(shí)工作。你應(yīng)該:

  1. 從原始網(wǎng)絡(luò)導(dǎo)出瓶頸到文件。

  2. 使用瓶頸結(jié)果作為輸入,使用另一個(gè)網(wǎng)絡(luò)來(lái)訓(xùn)練您的數(shù)據(jù)。


查看完整回答
反對(duì) 回復(fù) 2021-06-06
?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊

這樣的事情應(yīng)該工作(未經(jīng)測(cè)試):


# Serialize the data into two tfrecord files

tf.enable_eager_execution()

feature_extractor = ...

features_file = tf.python_io.TFRecordWriter('features.tfrec')

label_file = tf.python_io.TFRecordWriter('labels.tfrec')


for images, labels in dataset:

  features = feature_extractor(images)

  features_file.write(tf.serialize_tensor(features))

  label_file.write(tf.serialize_tensor(labels))

# Parse the files and zip them together

def parse(type, shape):

  _def parse(x):

    result = tf.parse_tensor(x, out_type=shape)

    result = tf.reshape(result, FEATURE_SHAPE)

    return result

  return parse


features_ds = tf.data.TFRecordDataset('features.tfrec')

features_ds = features_ds.map(parse(tf.float32, FEATURE_SHAPE), num_parallel_calls=AUTOTUNE)


labels_ds = tf.data.TFRecordDataset('labels.tfrec')

labels_ds = labels_ds.map(parse(tf.float32, FEATURE_SHAPE), num_parallel_calls=AUTOTUNE)


ds = tf.data.Dataset.zip(features_ds, labels_ds)

ds = ds.unbatch().shuffle().repeat().batch().prefetch()...

您也可以使用 來(lái)完成它Dataset.cache,但我不是 100% 確定細(xì)節(jié)。


查看完整回答
反對(duì) 回復(fù) 2021-06-06
  • 2 回答
  • 0 關(guān)注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)