簡體   English   中英

服務后的模型輸出與 keras 模型輸出不同

[英]Output of model after serving different with keras model output

我有一個輸入模型,其形狀類似於 (145, 24, 24, 3)

通過 tensorflow keras 輸出的模型負載將具有類似 (145, 4) 的形狀

但是當我將輸入從張量轉換為列表並將其發布到模型服務中時。

輸出返回 (,4)

我在 docker 中使用 tensorflow-serving

我的代碼:

        img_boxes = get_image_boxes(bboxes, img, height, width, num_boxes, size=24)
        img_in = tf.make_tensor_proto(img_boxes)
        img_in = tf.make_ndarray(img_in)
        print(img_in.shape) # (145, 24, 24, 3)

        # probs, offsets = self.rnet(img_boxes)
        payload = {'instances': img_in.tolist()}
        res = requests.post('http://localhost:8501/v1/models/r_net:predict', data=payload)
        res = res.json()['predictions'][0]
        probs = tf.convert_to_tensor(res['softmax'])
        offsets = tf.convert_to_tensor(res['dense5_2'])
        print(probs.shape) # (, 4)

我的模型:

    __________________________________________________________________________________________________
 Layer (type)                   Output Shape         Param #     Connected to                     
==================================================================================================
 input_1 (InputLayer)           [(None, 24, 24, 3)]  0           []                               
                                                                                                  
 permute (Permute)              (None, 24, 24, 3)    0           ['input_1[0][0]']                
                                                                                                  
 conv1 (Conv2D)                 (None, 22, 22, 28)   784         ['permute[0][0]']                
                                                                                                  
 prelu1 (PReLU)                 (None, 22, 22, 28)   28          ['conv1[0][0]']                  
                                                                                                  
 pool1 (MaxPooling2D)           (None, 11, 11, 28)   0           ['prelu1[0][0]']                 
                                                                                                  
 conv2 (Conv2D)                 (None, 9, 9, 48)     12144       ['pool1[0][0]']                  
                                                                                                  
 prelu2 (PReLU)                 (None, 9, 9, 48)     48          ['conv2[0][0]']                  
                                                                                                  
 pool2 (MaxPooling2D)           (None, 4, 4, 48)     0           ['prelu2[0][0]']                 
                                                                                                  
 conv3 (Conv2D)                 (None, 3, 3, 64)     12352       ['pool2[0][0]']                  
                                                                                                  
 prelu3 (PReLU)                 (None, 3, 3, 64)     64          ['conv3[0][0]']                  
                                                                                                  
 flatten (Flatten)              (None, 576)          0           ['prelu3[0][0]']                 
                                                                                                  
 dense4 (Dense)                 (None, 128)          73856       ['flatten[0][0]']                
                                                                                                  
 prelu4 (PReLU)                 (None, 128)          128         ['dense4[0][0]']                 
                                                                                                  
 dense5_1 (Dense)               (None, 2)            258         ['prelu4[0][0]']                 
                                                                                                  
 softmax (Softmax)              (None, 2)            0           ['dense5_1[0][0]']               
                                                                                                  
 dense5_2 (Dense)               (None, 4)            516         ['prelu4[0][0]']                 
                                                                                                  
==================================================================================================
Total params: 100,178
Trainable params: 100,178
Non-trainable params: 0
__________________________________________________________________________________________________

我的錯誤是我沒有在輸出中得到所有預測

res = res.json()['predictions'][0]

它應該是:

res = res.json()['predictions']

,輸出是一個數組字典,我需要用相同的鍵連接它們,我會得到我想要的輸出。 {'predictions': [{'softmax': [0.210848287, 0.789151728], 'dense5_2': [0.182407588, 0.159706563, 0.113356635, 0.401812047]}, {'softmax': [0.993124425, 0.0068756], 'dense5_2': [0.138127923, -0.0996344835, -0.020740509, -0.0633568913]}, {'softmax': [0.958264828, 0.0417351499], 'dense5_2': [0.0111884885, 0.0999818072, -0.130534053, 0.0480072]}, {'softmax': [0.983752847, 0.0162471626], 'dense5_2': [-0.0930862129, -0.224962771, 0.0652338713, 0.205662221]}, {'softmax': [0.947032034, 0.0529679693], 'dense5_2': [0.242067963, 0.0784763768, 0.0628610402, 0.109089941]}, {'softmax': [0.964857459, 0.0351425521], 'dense5_2': [0.210765839, 0.110972457, 0.0283354521, 0.210187465]},...]}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM