Tensorflow矩阵过大问题的解决
問(wèn)題:推薦系統(tǒng)中,用戶和物品矩陣進(jìn)行embedding,但矩陣過(guò)大時(shí),超過(guò)2G時(shí),會(huì)有如下提示
ValueError: Cannot create a tensor proto whose content is larger than 2GB.
出現(xiàn)問(wèn)題的代碼語(yǔ)句是:
self.user_item_embedding = tf.convert_to_tensor(matrix)
matrix是一個(gè)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)
先構(gòu)建占位符,在設(shè)置變量,并在sess.run時(shí)賦予:
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
總結(jié)
以上是生活随笔為你收集整理的Tensorflow矩阵过大问题的解决的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python绘制正态分布曲线
- 下一篇: 推荐经典算法实现之BPMF(pymc3+