Tensorflow1系、いまさらっていう感じですが、PointNetのgithubに上がっているものがTF1.0.1なので使っていました。ネットワークを変更したくて、デバッグのためにTensorの中身を見ながらやっていたのですが、中身をみる方法に困ったので書いておきます。(Tensorflow2系では、かなり改善されているみたい)

Tensorの中身を見る方法(大抵の場合)

printではみれないので、以下のようにsessionを使って中を見ることになります(参考

import tensorflow as tf

# データの用意
data = np.zeros((32,1024,4)).astype(np.float32)
data[:,:,1] = 1
data[:,:,2] = 2
data[:,:,3] = 3
data = tf.convert_to_tensor(data)

with tf.Session() as sess:   
    print(data.eval())

計算グラフとして格納されているので、「計算を実行しないと結果が見れない」ということだと理解しています。そのため、少々複雑な状況ではdata.eval()のところで、以下のようなエラーが出る場合があります。

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value transform_net1/tconv1/weights

上記エラーが出る理由とその解決

上記のエラーが出たのは以下のようなコードでした。

def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    with tf.variable_scope('transform_net1') as sc:
        print("point cloud: {}".format(point_cloud))
        transform = input_transform_net(point_cloud, is_training, bn_decay, K=3)
    point_cloud_transformed = tf.matmul(point_cloud[:, :, 0:3], transform)
    input_image = tf.expand_dims(point_cloud_transformed, -1)

    with tf.Session() as sess:   
        print(input_image.eval())  # ここでエラーが発生 #######################################

input_imageの値を確認したくて、sessionを使ってデータを表示しようとしたところ、先程のエラーが置きました。PointNetで、input_imageは入力のpoint_cloudを

    transform = input_transform_net(point_cloud, is_training, bn_decay, K=3)

のところでtransform_netを通してアフィン変換(のようなこと)を行っています。つまり、別のネットワークを通した結果がinput_image担っています。

その為、その計算を実行しようとしたら未定義の値(transform_net1/tconv1/weights)が使われているというエラーが出てしまいました。

よって、sessionを開始した後に初期化をしてあげれば良いわけです。

def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    with tf.variable_scope('transform_net1') as sc:
        print("point cloud: {}".format(point_cloud))
        transform = input_transform_net(point_cloud, is_training, bn_decay, K=3)
    point_cloud_transformed = tf.matmul(point_cloud[:, :, 0:3], transform)
    input_image = tf.expand_dims(point_cloud_transformed, -1)

    init = tf.initialize_all_variables()    # 追加1 #######################
    with tf.Session() as sess:   
        sess.run(init)    # 追加2 #######################
        print("input_images")

私の問題では、これで解決できました!

Categories:

No responses yet

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA