简体   繁体   中英

Tensor flow transfer learning

If we use pre-trained network for transfer learning then does sess.run(tf.global_variables_initializer())
also initialize pretrained weight or not?

if i don't use this then I gets error like this-

FailedPreconditionError:Attempting to use uninitialized value train/beta2_power_1

i am using new Adam optimiser named as "new_Adam"

train_step = tf.train.AdamOptimizer(1e-4, name="new_Adam").minimize(cross_entropy)

my old model already has an Adam node and not letting me to redefine with same name.

Actually my concern is that i want to do transfer learning where I am not sure whether sess.run(tf.global_variables_initializer()) change my trained weights. How can i go for proper transfer learning?

You can initialize your pre-trained model by import your weights model. for example

base_model = keras.applications.MobileNetV2(input_shape=in_img ,include_top=False, weights='mobilenetv2.h5')

then apply your own network

out_class=10
x=base_model.output
x=GlobalAveragePooling2D()(x)
x=Dense(1024,activation='relu')(x) 
x=Dense(1024,activation='relu')(x)
x=Dense(512,activation='relu')(x) 
preds=Dense(out_class,activation='softmax')(x) 
model=Model(inputs=base_model.input,outputs=preds) 

out_class is number of classification

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM