leliyliu / ICS

智能计算系统课程(陈云霁)课后作业记录
55 stars 20 forks source link

[Error]How to solve the error : AttributeError: 'module' object has no attribute 'power_difference' #6

Open t22akeru opened 3 years ago

t22akeru commented 3 years ago
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'

↑This error appears when executing “ .../online_mlu/power_difference_test_bcl.py” ↓

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()

Could you tell me how to fix it? 谢谢

leliyliu commented 3 years ago

This problem may caused by the tensorflow version, I'm not sure if it has deprecated this op, maybe you can check another network which contains the same op