Tensorflow矩阵过大问题的解决
問題:推薦系統中,用戶和物品矩陣進行embedding,但矩陣過大時,超過2G時,會有如下提示
ValueError: Cannot create a tensor proto whose content is larger than 2GB.
出現問題的代碼語句是:
self.user_item_embedding = tf.convert_to_tensor(matrix)
matrix是一個numpy的大型矩陣。
解決:
?matrix_init = tf.placeholder(tf.float32, shape=(self.shape[0], self.shape[1]))
?matrixV = tf.Variable(matrix_init)
self.user_item_embedding = tf.convert_to_tensor(matrixV)
先構建占位符,在設置變量,并在sess.run時賦予:
elf.sess.run(tf.global_variables_initializer(), feed_dict={matrix_init: matrix})
參考:
https://stackoverflow.com/questions/51470991/create-a-tensor-proto-whose-content-is-larger-than-2gb
https://stackoverflow.com/questions/35394103/initializing-tensorflow-variable-with-an-array-larger-than-2gb
總結
以上是生活随笔為你收集整理的Tensorflow矩阵过大问题的解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python绘制正态分布曲线
- 下一篇: 推荐经典算法实现之BPMF(pymc3+