0

下記のコードを実行すると、エラーメッセージが表示されてしまいます。
どなたか解決方法がわかる方教えてください。

エラーメッセージ:

WARNING:tensorflow:From power_difference_test_bcl.py:10: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

CNML: 7.2.1 c8ada41
CNRT: 4.2.1 fa5e44c
CNML: 7.2.1 c8ada41
CNML: 7.2.1 c8ada41
2020-12-05 05:24:10.892081: I tensorflow/stream_executor/mlu/mlu_stream_executor.cc:470][112186] MLU OP Cache enabled
CNML: 7.2.1 c8ada41
2020-12-05 05:24:10.892249: I tensorflow/core/common_runtime/mlu/mlu_device.cc:396][112186] __LOG_MLU__, Current MLU_Visible_Devices Count: 1
2020-12-05 05:24:10.892410: I tensorflow/core/common_runtime/mlu/mlu_device.cc:115][112186] __LOG_MLU__, save_offline_model: 0
2020-12-05 05:24:10.892487: I tensorflow/core/common_runtime/mlu/mlu_device.cc:121][112186] __LOG_MLU__, core_version: MLU270
2020-12-05 05:24:10.892584: I tensorflow/core/common_runtime/mlu/mlu_device.cc:123][112186] __LOG_MLU__, core_num: 1
Traceback (most recent call last):
  File "power_difference_test_bcl.py", line 36, in <module>
    main()
  File "power_difference_test_bcl.py", line 22, in main
    res = power_difference_op(input_x, input_y, input_pow)
  File "power_difference_test_bcl.py", line 12, in power_difference_op
    out = tf.power_difference()
  File "/opt/AICSE-demo-student/env/tensorflow-v1.10/virtualenv_mlu/local/lib/python2.7/site-packages/tensorflow/python/util/deprecation_wrapper.py", line 106, in __getattr__
    attr = getattr(self._dw_wrapped_module, name)
AttributeError: 'module' object has no attribute 'power_difference'

ソースコード:

import numpy as np
import os
import time
os.environ['MLU_VISIBLE_DEVICES']="0"
import tensorflow as tf
np.set_printoptions(suppress=True)
from power_diff_numpy import *

def power_difference_op(input_x, input_y, input_pow):
        with tf.Session() as sess:

                out = tf.power_difference()
                return sess.run(out, feed_dict = {x:input_x, y:input_y, pow:input_pow})

def main():
        value = 256
        input_x = np.random.randn(1,value,value,3)
        input_y = np.random.randn(1,1,1,3)
        input_pow = np.zeros((2))

        start = time.time()
        res = power_difference_op(input_x, input_y, input_pow)
        end = time.time() - start
        print("comput BCL op cost "+ str(end*1000) + "ms" )

        start = time.time()
        output = power_diff_numpy(input_x, input_y,len(input_pow))
        end = time.time()
        res = np.reshape(res,(-1))
        output = np.reshape(output,(-1))
        print("comput op cost "+ str((end-start)*1000) + "ms" )
        err = sum(abs(res - output))/sum(output)
        print("err rate= "+ str(err*100))

if __name__ == '__main__':
        main()   
6
  • 「The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.」というWarningも出ています。新しいバージョン(2.x)のtensorflowにすると解決するかもしれません。
    – Fumu 7
    2020年12月6日 3:13
  • 実はtensorflowのバージョンを2ではないですけどアップデートしてみたらwarningは消えましたが下のエラーはそのままでした。
    – Tak
    2020年12月6日 5:12
  • こちらの質問 pythonエラーAttributeError: 'module' object has no attribute 'power_difference'について と同じ内容に見えますが、件のリポジトリを眺めてみると tensorflow の plugin として作成した shared library を読み込む必要があり(ソースコードはおそらくICS/power_difference.cc at master · leliyliu/ICS)、それがコメントの TODO: 〜 として書かれている様です。
    – user39889
    2020年12月6日 11:50
  • @metropolis ご回答ありがとうございます。あまりstack overflow使い慣れてないので重複してしまいました。恐縮ですが、 shared library を読み込む と言うのは具体的にどんなコードで実現できるのでしょうか
    – Tak
    2020年12月6日 12:06
  • power_difference の実行方法に関してはICS/lab1.md at master · leliyliu/ICSに記載されている様に読めるのですが(中国語で書かれているので DeepLで翻訳して読んでいます)、python API が見当たりません。
    – user39889
    2020年12月6日 12:14

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。