小编Cos*_*pel的帖子

numpy中1d数组的乘法

我有两个1d向量(在某些情况下它们也可以是2d矩阵).我找到了点积的点函数,但是如果我想将a.dot(b)与这些形状相乘:

a = [1,0.2,...]
a.shape = (10,)
b = [2.3,4,...]
b.shape = (21,)
a.dot(b) and I get ValueError: matrices not aligned.
Run Code Online (Sandbox Code Playgroud)

而且我想做

c = a.dot(b)
c.shape = (10,21)
Run Code Online (Sandbox Code Playgroud)

有什么想法怎么做?我试过转置功能,但它不起作用.

python numpy vector matrix

9
推荐指数
1
解决办法
1万
查看次数

在 Tensorflow2 中将图形冻结为 pb

我们从 TF1 部署了许多模型,通过图形冻结保存它们:

tf.train.write_graph(self.session.graph_def, some_path)

# get graph definitions with weights
output_graph_def = tf.graph_util.convert_variables_to_constants(
        self.session,  # The session is used to retrieve the weights
        self.session.graph.as_graph_def(),  # The graph_def is used to retrieve the nodes
        output_nodes,  # The output node names are used to select the usefull nodes
)

# optimize graph
if optimize:
    output_graph_def = optimize_for_inference_lib.optimize_for_inference(
            output_graph_def, input_nodes, output_nodes, tf.float32.as_datatype_enum
    )

with open(path, "wb") as f:
    f.write(output_graph_def.SerializeToString())
Run Code Online (Sandbox Code Playgroud)

然后通过以下方式加载它们:

with tf.Graph().as_default() as graph:
    with graph.device("/" + args[name].processing_unit):
        tf.import_graph_def(graph_def, name="")
            for key, …
Run Code Online (Sandbox Code Playgroud)

python machine-learning tensorflow tensorflow2.0

9
推荐指数
3
解决办法
4892
查看次数

从张量流模型中获取权重

您好我想从tensorflow中微调VGG模型.我有两个问题.

如何从网络获得权重?trainable_variables为我返回空列表.

我从这里使用现有的模型:https://github.com/ry/tensorflow-vgg16.我发现了关于获取权重的帖子,但由于import_graph_def这对我不起作用.在TensorFlow训练的模型中获取一些权重的值

import tensorflow as tf
import PIL.Image
import numpy as np

with open("../vgg16.tfmodel", mode='rb') as f:
  fileContent = f.read()

graph_def = tf.GraphDef()
graph_def.ParseFromString(fileContent)

images = tf.placeholder("float", [None, 224, 224, 3])

tf.import_graph_def(graph_def, input_map={ "images": images })
print("graph loaded from disk")

graph = tf.get_default_graph()

cat = np.asarray(PIL.Image.open('../cat224.jpg'))
print(cat.shape)
init = tf.initialize_all_variables()

with tf.Session(graph=graph) as sess:
  print(tf.trainable_variables() )
  sess.run(init)
Run Code Online (Sandbox Code Playgroud)

python neural-network conv-neural-network tensorflow

5
推荐指数
1
解决办法
5239
查看次数

如何将大量数据传递给芹菜

我正在使用celery worker从我的机器学习模型中获取结果。

我正在做的是从客户端向celery任务发送并返回大的numpy数组(几兆字节)。

目前,我正在将客户端numpy数组序列化为base64。当我直接从客户端或celery worker上的Redis存储/获取数据时,系统的性能要比/当我让celery完成所有参数传递(numpy的base64)时的系统性能要快得多。

我也想使用celery(带有'redis'代理)来传递args / numpy数组,而不是直接在客户端中进行redis。您知道哪里可能出问题吗?我如何设置celery的配置以更有效地做到这一点(在客户端->经纪人->工人之间传递数据,然后再传回客户端)。

        serialized = np.asarray(images).reshape((number_of_records, size)).ravel().tostring()
        serialized = base64.b64encode(serialized)
        #self.redis.set(key, serialized)

        print('calling celery processor')
        result = self.celery.send_task('process', args=[number_of_records, serialized], kwargs={})
        returncode, result = result.get(timeout=1000, interval=0.1) 
Run Code Online (Sandbox Code Playgroud)

vs(这是更快,直接使用redis存储):

        serialized = np.asarray(images).reshape((number_of_records, size)).ravel().tostring()
        serialized = base64.b64encode(serialized)
        self.redis.set(key, serialized)

        print('calling celery processor')
        result = self.celery.send_task('process', args=[number_of_records, key], kwargs={})
        returncode, result = result.get(timeout=1000, interval=0.1) 

        resultc= self.redis.get(key)
Run Code Online (Sandbox Code Playgroud)

有关celery进行序列化,配置设置等的任何技巧?我希望该系统快速简单。我是否应该像第二个示例一样直接使用redis?

python serialization numpy redis celery

5
推荐指数
1
解决办法
949
查看次数