I'm still new to tensor flow, so I'm sorry if this is a naive question. I am trying to use the inception_V4 site model. In addition, I use my network as is, I mean published on my site .
This is what I call the network:
def network(images_op, keep_prob): width_needed_InceptionV4Net = 342 shape = images_op.get_shape().as_list() H = int(round(width_needed_InceptionV4Net * shape[1] / shape[2], 2)) resized_images = tf.image.resize_images(images_op, [width_needed_InceptionV4Net, H], tf.image.ResizeMethod.BILINEAR) with slim.arg_scope(inception.inception_v4_arg_scope()): logits, _ = inception.inception_v4(resized_images, num_classes=20, is_training=True, dropout_keep_prob = keep_prob) return logits
Since I need to reset the final inception_V4 level for my categories, I changed the number of classes to 20, as you can see in the method call ( inception.inception_v4 ).
Here is the train method that I still have:
def optimistic_restore(session, save_file, flags): reader = tf.train.NewCheckpointReader(save_file) saved_shapes = reader.get_variable_to_shape_map() var_names = sorted([(var.name, var.name.split(':')[0]) for var in tf.global_variables() if var.name.split(':')[0] in saved_shapes]) restore_vars = [] name2var = dict(zip(map(lambda x:x.name.split(':')[0], tf.global_variables()), tf.global_variables())) if flags.checkpoint_exclude_scopes is not None: exclusions = [scope.strip() for scope in flags.checkpoint_exclude_scopes.split(',')] with tf.variable_scope('', reuse=True): variables_to_init = [] for var_name, saved_var_name in var_names: curr_var = name2var[saved_var_name] var_shape = curr_var.get_shape().as_list() if var_shape == saved_shapes[saved_var_name]: print(saved_var_name) excluded = False for exclusion in exclusions: if saved_var_name.startswith(exclusion): variables_to_init.append(var) excluded = True break if not excluded: restore_vars.append(curr_var) saver = tf.train.Saver(restore_vars) saver.restore(session, save_file) def train(images, ids, labels, total_num_examples, batch_size, train_dir, network, flags, optimizer, log_periods, resume): """ !@brief Trains the network for a number of steps. @param images image tensor @param ids id tensor @param labels label tensor @param total_num_examples total number of training examples @param batch_size batch size @param train_dir directory where checkpoints should be saved @param network pointer to a function describing the network @param flags command-line arguments @param optimizer pointer to the optimization class @param log_periods list containing the step intervals at which 1) logs should be printed, 2) logs should be saved for TensorBoard and 3) variables should be saved @param resume should training be resumed (or restarted from scratch)? @return the number of training steps performed since the first call to 'train' """
I added a flag in a python script called checkpoint_exclude_scopes where I determine exactly which tensors should not be restored. This is necessary to change the number of classes in the last layer of the network. This is what I call a python script:
./toolDetectionInceptions.py
My first tests were terrible because I had too many problems .. something like:
tensorflow.python.framework.errors.NotFoundError: Tensor name "InceptionV4/Mixed_6b/Branch_3/Conv2d_0b_1x1/weights/read:0" not found in checkpoint files
After some googling, I could find a workaround on this site , where they suggest using the optimistic_restore function presented in the code above, including some of its modifications.
But now the problem is different:
W tensorflow/core/framework/op_kernel.cc:993] Failed precondition: Attempting to use uninitialized value Variable [[Node: Variable/read = Identity[T=DT_INT32, _class=["loc:@Variable"], _device="/job:localhost/replica:0/task:0/cpu:0"](Variable)]]
There seems to be a local variable that is not initialized, but I could not find it. Can you please help?
Edition:
To debug this problem, I checked the number of variables that need to be initialized and restored by adding some logs to the optimistic_restore function. Here is a quick one:
# saved_shapes 609
For your information, CheckpointReader.get_variable_to_shape_map(): returns the names of the bit mapping tensors to ints lists representing the shape of the corresponding tensor at the breakpoint. This means that the number of variables at this breakpoint is 609 , and the total number of variables needed for recovery is 1519 .
There seems to be a huge gap between the preliminary control point tensors and the variables used by the network architecture (actually their network). Is there any compression at the checkpoint? Is that what I'm saying? Now I know what is missing: it is just the initialization of variables that have not been restored. However, I need to know why there is a huge difference between their InceptionV4 network architecture and the pre-processed checkpoint?