yinguobing / cnn-facial-landmark

Training code for facial landmark detection based on deep convolutional neural network.
MIT License
623 stars 183 forks source link

Unable to use the fronze graph #70

Open myw2s-git opened 4 years ago

myw2s-git commented 4 years ago

Hi,

I can freeze the exported model by using the following script:

python3 freeze_graph.py \ --input_saved_model_dir=$SAVED_MODEL_DIR \ --output_node_names=layer6/logits/BiasAdd \ --output_graph=./frozen_graph/frozengraph$SNAPSHOT_TIMESTAMP.pb

However, when I tried to use this fronze graph. There are errors occurred.

ValueError: Cannot feed value of shape (128, 128, 3) for Tensor 'input_image_tensor:0', which has shape '(?, ?, ?, 3)'

I made a change to the function "detect_marks":

the input argument of get_tensor_by_name from 'logits/BiasAdd:0' to 'layer6/logits/BiasAdd:0'.

def detect_marks(self, image_np):
    """Detect marks from image"""
    # Get result tensor by its name.
    if DEBUG_NEW_MODEL:
        logits_tensor = self.graph.get_tensor_by_name('layer6/logits/BiasAdd:0')
    else:
        logits_tensor = self.graph.get_tensor_by_name('logits/BiasAdd:0')

    # Actual detection.
    predictions = self.sess.run(logits_tensor, feed_dict={'input_image_tensor:0': image_np})

    # Convert predictions to landmarks.
    marks = np.array(predictions).flatten()
    marks = np.reshape(marks, (-1, 2))
    return marks

Then, I use tensorboard to open your frozen_inference_graph.pb. The input_image_tensor is 128x128x3. But, my frozen graph shows the input_image_tensor is ? x ? x ? x 3. I guess this is the problem. Howeverm I don't have any idea to fix it. Don't you??

Thank you very much!
Jason

yinguobing commented 4 years ago

The input shape takes the form of (Batch size, Height, Width, Channel size). The question mark means the number is not specified. The error message is actually quite common, it means the tensor shape of the input you provided is not as expected by the graph.

You can expand the input dimension by making it a list like this.