remove action from AMP plugin

Fixed it by changing to

add_action( 'wp_enqueue_scripts', 'remove_hooks' );

function remove_hooks(){
    global $wp_query;
    $postid = $wp_query->post->ID;
    $format = get_post_format( $postid );

    if ($format == 'gallery') {
    remove_action('wp_head', 'amp_frontend_add_canonical',10);
    }
}