小编Pra*_*jal的帖子

加载已保存的模型后得出错误的预测

我试图保存Estimator,然后加载它以根据需要进行预测.我训练模型的部分:

classifier = tf.estimator.Estimator(model_fn=bag_of_words_model)

# Train
train_input_fn = tf.estimator.inputs.numpy_input_fn(
    x={"words": x_train},  # x_train is 2D numpy array of shape (26, 5)
    y=y_train,                   # y_train is 1D panda series of length 26
    batch_size=1000,
    num_epochs=None,
    shuffle=True)

classifier.train(input_fn=train_input_fn, steps=300)
Run Code Online (Sandbox Code Playgroud)

然后我按如下方式保存模型:

def serving_input_receiver_fn():
    serialized_tf_example = tf.placeholder(dtype=tf.int64, shape=(None, 5), name='words')
    receiver_tensors = {"predictor_inputs": serialized_tf_example}
    features = {"words": tf.tile(serialized_tf_example, multiples=[1, 1])}
    return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)

full_model_dir = classifier.export_savedmodel(export_dir_base="E:/models/",
                                              serving_input_receiver_fn=serving_input_receiver_fn)
Run Code Online (Sandbox Code Playgroud)

我现在加载模型并将测试集提供给它进行预测:

from tensorflow.contrib import predictor

classifier = predictor.from_saved_model("E:\\models\\1547122667")
predictions = classifier({'predictor_inputs': x_test})
print(predictions)
Run Code Online (Sandbox Code Playgroud)

这给了我预测,如:

{'class': array([ …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

7
推荐指数
1
解决办法
652
查看次数

有没有办法在运行时动态更改 docker 容器的 CPU 数量?

我想知道 docker 提供的功能或 Linux 的功能是否可以用来更改运行时分配给 docker 容器的 CPU?

例如:

我运行一个名为 test:1.0 的映像,将其绑定为 4 个核心中的 2 个:

$ docker run --cpuset-cpus=0,1 test:1.0
Run Code Online (Sandbox Code Playgroud)

现在,这保证了容器将有 2 个核心,且利用率为 100%。我想做的是在运行时更改容器分配的 CPU。因此,如果我觉得没有其他进程在使用它,我想再给它 1 个核心。或者,如果我觉得其他进程需要它,则将其已给定的核心数减少 1。在此更改期间容器应保持运行。

docker

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

将二维数组传递给 C++ 中的函数

我正在尝试将二维数组传递给 C++ 中的函数。问题是它的量纲不是普遍常数。我将维度作为用户的输入,然后尝试传递数组。这是我正在做的事情:

/*
 * boy.cpp
 *
 *  Created on: 05-Oct-2014
 *      Author: pranjal
 */
#include<iostream>
#include<cstdlib>
using namespace std;


class Queue{
private:
    int array[1000];
    int front=0,rear=0;
public:
    void enqueue(int data){
        if(front!=(rear+1)%1000){
            array[rear++]=data;
        }
    }
    int dequeue(){
        return array[front++];
    }
    bool isEmpty(){
        if(front==rear)
            return true;
        else
            return false;
    }
};

class Graph{
public:
    void input(int matrix[][],int num_h){ //this is where I am passing the matrix
        int distance;
        char ans;

        for(int i=0;i<num_h;i++){
            for(int j=0;j<num_h;j++)
                matrix[i][j]=0;
        }
        for(int i=0;i<num_h;i++){
            for(int j=i+1;j<num_h;j++){
                cout<<"Is …
Run Code Online (Sandbox Code Playgroud)

c++ arrays class function

2
推荐指数
1
解决办法
9151
查看次数

根据另一个列表对元组列表进行排序

我有一个元组列表,例如。

l1 = [(1, 'a', 'x'), (2, 'b', 'y'), (3, 'a', 'z'), (4, 'c', 'xyz')]
Run Code Online (Sandbox Code Playgroud)

我还有另一个清单

l2 = ['a', 'b', 'c']
Run Code Online (Sandbox Code Playgroud)

我想l1根据 中存在的顺序对每个元组的第二个值进行排序l2。最终结果应该是

l1 = [(1, 'a', 'x'), (3, 'a', 'z'), (2, 'b', 'y'), (4, 'c', 'xyz')]
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,第二个值为 的元组a首先出现,然后是具有第二个值的元组b,最后是具有 的元组c。

我写了以下内容:

l = []
for i in l2:
    for j in l1:
        if i == j(1):
        l.append(j)
Run Code Online (Sandbox Code Playgroud)

这非常简单。但我想知道是否有任何 pythonic 方法来完成这件事?

python

2
推荐指数
1
解决办法
1015
查看次数

标签 统计

python ×2

arrays ×1

c++ ×1

class ×1

docker ×1

function ×1

tensorflow ×1