After running fine tuning , but the accuracy became worse after training. I don’t know why.
My network is very simple, just one layer, the training set is mnist. After training, the weight didn’t change, but the bias changed significantly.
-
this is the model
inputs = Input((IMG_SIZEX, IMG_SIZEY))
x = Flatten()(inputs)
output = Dense(10, activation = ‘softmax’)(x)
model = Model(inputs, output)
optimizer = Adam(lr=0.001)
loss_fn = tf.keras.losses.CategoricalCrossentropy(from_logits=False)
model.compile(optimizer = optimizer,
loss = loss_fn, metrics=[‘accuracy’])
2)The fine tuning code is below.
def training_helper(sim, generator):
g = sim.session.graph
sess = sim.session
with g.as_default():
x = sim.session.graph.get_tensor_by_name(“input_2:0”)
y = g.get_tensor_by_name(“dense_1/Softmax:0”)
#fc1_w = g.get_tensor_by_name(“/ReadVariableOp:0”)
ce = g.get_tensor_by_name("loss/dense_1_loss/softmax_cross_entropy_with_logits/Reshape:0")
# Using Adam optimizer
train_step = tf.compat.v1.train.AdamOptimizer(1e-3, name="TempAdam").minimize(ce)
graph_eval.initialize_uninitialized_vars(sess)
# Input data for MNIST
# Using 100 iterations and batch of size 100
for j in range(10):
for i in range(600):
inputdata= x_train[i*100:i*100+100,:,:]
outputdata = y_train[i*100:i*100+100]
outputdata = tf.keras.utils.to_categorical(outputdata, 10)
sess.run(train_step, feed_dict={x: inputdata, y:outputdata})