keras pretrained模型应用于新的数据应当如何设置输入格式 20C

网络模型为:

Model Summary:
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
img (InputLayer)                (None, 427, 561, 3)  0                                            
__________________________________________________________________________________________________
dmap (InputLayer)               (None, 427, 561, 3)  0                                            
__________________________________________________________________________________________________
padding1_1 (ZeroPadding2D)      (None, 429, 563, 3)  0           img[0][0]                        
__________________________________________________________________________________________________
padding1_1d (ZeroPadding2D)     (None, 429, 563, 3)  0           dmap[0][0]                       
__________________________________________________________________________________________________
conv1_1 (Conv2D)                (None, 427, 561, 64) 1792        padding1_1[0][0]                 
__________________________________________________________________________________________________
conv1_1d (Conv2D)               (None, 427, 561, 64) 1792        padding1_1d[0][0]                
__________________________________________________________________________________________________
padding1_2 (ZeroPadding2D)      (None, 429, 563, 64) 0           conv1_1[0][0]                    
__________________________________________________________________________________________________
padding1_2d (ZeroPadding2D)     (None, 429, 563, 64) 0           conv1_1d[0][0]                   
__________________________________________________________________________________________________
conv1_2 (Conv2D)                (None, 427, 561, 64) 36928       padding1_2[0][0]                 
__________________________________________________________________________________________________
conv1_2d (Conv2D)               (None, 427, 561, 64) 36928       padding1_2d[0][0]                
__________________________________________________________________________________________________
pool1 (MaxPooling2D)            (None, 214, 281, 64) 0           conv1_2[0][0]                    
__________________________________________________________________________________________________
pool1d (MaxPooling2D)           (None, 214, 281, 64) 0           conv1_2d[0][0]                   
__________________________________________________________________________________________________
padding2_1 (ZeroPadding2D)      (None, 216, 283, 64) 0           pool1[0][0]                      
__________________________________________________________________________________________________
padding2_1d (ZeroPadding2D)     (None, 216, 283, 64) 0           pool1d[0][0]                     
__________________________________________________________________________________________________
conv2_1 (Conv2D)                (None, 214, 281, 128 73856       padding2_1[0][0]                 
__________________________________________________________________________________________________
conv2_1d (Conv2D)               (None, 214, 281, 128 73856       padding2_1d[0][0]                
__________________________________________________________________________________________________
padding2_2 (ZeroPadding2D)      (None, 216, 283, 128 0           conv2_1[0][0]                    
__________________________________________________________________________________________________
padding2_2d (ZeroPadding2D)     (None, 216, 283, 128 0           conv2_1d[0][0]                   
__________________________________________________________________________________________________
conv2_2 (Conv2D)                (None, 214, 281, 128 147584      padding2_2[0][0]                 
__________________________________________________________________________________________________
conv2_2d (Conv2D)               (None, 214, 281, 128 147584      padding2_2d[0][0]                
__________________________________________________________________________________________________
pool2 (MaxPooling2D)            (None, 107, 141, 128 0           conv2_2[0][0]                    
__________________________________________________________________________________________________
pool2d (MaxPooling2D)           (None, 107, 141, 128 0           conv2_2d[0][0]                   
__________________________________________________________________________________________________
padding3_1 (ZeroPadding2D)      (None, 109, 143, 128 0           pool2[0][0]                      
__________________________________________________________________________________________________
padding3_1d (ZeroPadding2D)     (None, 109, 143, 128 0           pool2d[0][0]                     
__________________________________________________________________________________________________
conv3_1 (Conv2D)                (None, 107, 141, 256 295168      padding3_1[0][0]                 
__________________________________________________________________________________________________
conv3_1d (Conv2D)               (None, 107, 141, 256 295168      padding3_1d[0][0]                
__________________________________________________________________________________________________
bn_conv3_1 (BatchNormalization) (None, 107, 141, 256 1024        conv3_1[0][0]                    
__________________________________________________________________________________________________
bn_conv3_1d (BatchNormalization (None, 107, 141, 256 1024        conv3_1d[0][0]                   
__________________________________________________________________________________________________
relu3_1 (Activation)            (None, 107, 141, 256 0           bn_conv3_1[0][0]                 
__________________________________________________________________________________________________
relu3_1d (Activation)           (None, 107, 141, 256 0           bn_conv3_1d[0][0]                
__________________________________________________________________________________________________
padding3_2 (ZeroPadding2D)      (None, 109, 143, 256 0           relu3_1[0][0]                    
__________________________________________________________________________________________________
padding3_2d (ZeroPadding2D)     (None, 109, 143, 256 0           relu3_1d[0][0]                   
__________________________________________________________________________________________________
conv3_2 (Conv2D)                (None, 107, 141, 256 590080      padding3_2[0][0]                 
__________________________________________________________________________________________________
conv3_2d (Conv2D)               (None, 107, 141, 256 590080      padding3_2d[0][0]                
__________________________________________________________________________________________________
bn_conv3_2 (BatchNormalization) (None, 107, 141, 256 1024        conv3_2[0][0]                    
__________________________________________________________________________________________________
bn_conv3_2d (BatchNormalization (None, 107, 141, 256 1024        conv3_2d[0][0]                   
__________________________________________________________________________________________________
relu3_2 (Activation)            (None, 107, 141, 256 0           bn_conv3_2[0][0]                 
__________________________________________________________________________________________________
relu3_2d (Activation)           (None, 107, 141, 256 0           bn_conv3_2d[0][0]                
__________________________________________________________________________________________________
padding3_3 (ZeroPadding2D)      (None, 109, 143, 256 0           relu3_2[0][0]                    
__________________________________________________________________________________________________
padding3_3d (ZeroPadding2D)     (None, 109, 143, 256 0           relu3_2d[0][0]                   
__________________________________________________________________________________________________
conv3_3 (Conv2D)                (None, 107, 141, 256 590080      padding3_3[0][0]                 
__________________________________________________________________________________________________
conv3_3d (Conv2D)               (None, 107, 141, 256 590080      padding3_3d[0][0]                
__________________________________________________________________________________________________
bn_conv3_3 (BatchNormalization) (None, 107, 141, 256 1024        conv3_3[0][0]                    
__________________________________________________________________________________________________
bn_conv3_3d (BatchNormalization (None, 107, 141, 256 1024        conv3_3d[0][0]                   
__________________________________________________________________________________________________
relu3_3 (Activation)            (None, 107, 141, 256 0           bn_conv3_3[0][0]                 
__________________________________________________________________________________________________
relu3_3d (Activation)           (None, 107, 141, 256 0           bn_conv3_3d[0][0]                
__________________________________________________________________________________________________
pool3 (MaxPooling2D)            (None, 54, 71, 256)  0           relu3_3[0][0]                    
__________________________________________________________________________________________________
pool3d (MaxPooling2D)           (None, 54, 71, 256)  0           relu3_3d[0][0]                   
__________________________________________________________________________________________________
padding4_1 (ZeroPadding2D)      (None, 56, 73, 256)  0           pool3[0][0]                      
__________________________________________________________________________________________________
padding4_1d (ZeroPadding2D)     (None, 56, 73, 256)  0           pool3d[0][0]                     
__________________________________________________________________________________________________
conv4_1 (Conv2D)                (None, 54, 71, 512)  1180160     padding4_1[0][0]                 
__________________________________________________________________________________________________
conv4_1d (Conv2D)               (None, 54, 71, 512)  1180160     padding4_1d[0][0]                
__________________________________________________________________________________________________
bn_conv4_1 (BatchNormalization) (None, 54, 71, 512)  2048        conv4_1[0][0]                    
__________________________________________________________________________________________________
bn_conv4_1d (BatchNormalization (None, 54, 71, 512)  2048        conv4_1d[0][0]                   
__________________________________________________________________________________________________
relu4_1 (Activation)            (None, 54, 71, 512)  0           bn_conv4_1[0][0]                 
__________________________________________________________________________________________________
relu4_1d (Activation)           (None, 54, 71, 512)  0           bn_conv4_1d[0][0]                
__________________________________________________________________________________________________
padding4_2 (ZeroPadding2D)      (None, 56, 73, 512)  0           relu4_1[0][0]                    
__________________________________________________________________________________________________
padding4_2d (ZeroPadding2D)     (None, 56, 73, 512)  0           relu4_1d[0][0]                   
__________________________________________________________________________________________________
conv4_2 (Conv2D)                (None, 54, 71, 512)  2359808     padding4_2[0][0]                 
__________________________________________________________________________________________________
conv4_2d (Conv2D)               (None, 54, 71, 512)  2359808     padding4_2d[0][0]                
__________________________________________________________________________________________________
bn_conv4_2 (BatchNormalization) (None, 54, 71, 512)  2048        conv4_2[0][0]                    
__________________________________________________________________________________________________
bn_conv4_2d (BatchNormalization (None, 54, 71, 512)  2048        conv4_2d[0][0]                   
__________________________________________________________________________________________________
relu4_2 (Activation)            (None, 54, 71, 512)  0           bn_conv4_2[0][0]                 
__________________________________________________________________________________________________
relu4_2d (Activation)           (None, 54, 71, 512)  0           bn_conv4_2d[0][0]                
__________________________________________________________________________________________________
padding4_3 (ZeroPadding2D)      (None, 56, 73, 512)  0           relu4_2[0][0]                    
__________________________________________________________________________________________________
padding4_3d (ZeroPadding2D)     (None, 56, 73, 512)  0           relu4_2d[0][0]                   
__________________________________________________________________________________________________
conv4_3 (Conv2D)                (None, 54, 71, 512)  2359808     padding4_3[0][0]                 
__________________________________________________________________________________________________
conv4_3d (Conv2D)               (None, 54, 71, 512)  2359808     padding4_3d[0][0]                
__________________________________________________________________________________________________
bn_conv4_3 (BatchNormalization) (None, 54, 71, 512)  2048        conv4_3[0][0]                    
__________________________________________________________________________________________________
bn_conv4_3d (BatchNormalization (None, 54, 71, 512)  2048        conv4_3d[0][0]                   
__________________________________________________________________________________________________
relu4_3 (Activation)            (None, 54, 71, 512)  0           bn_conv4_3[0][0]                 
__________________________________________________________________________________________________
relu4_3d (Activation)           (None, 54, 71, 512)  0           bn_conv4_3d[0][0]                
__________________________________________________________________________________________________
pool4 (MaxPooling2D)            (None, 27, 36, 512)  0           relu4_3[0][0]                    
__________________________________________________________________________________________________
pool4d (MaxPooling2D)           (None, 27, 36, 512)  0           relu4_3d[0][0]                   
__________________________________________________________________________________________________
padding5_1 (ZeroPadding2D)      (None, 29, 38, 512)  0           pool4[0][0]                      
__________________________________________________________________________________________________
padding5_1d (ZeroPadding2D)     (None, 29, 38, 512)  0           pool4d[0][0]                     
__________________________________________________________________________________________________
conv5_1 (Conv2D)                (None, 27, 36, 512)  2359808     padding5_1[0][0]                 
__________________________________________________________________________________________________
conv5_1d (Conv2D)               (None, 27, 36, 512)  2359808     padding5_1d[0][0]                
__________________________________________________________________________________________________
bn_conv5_1 (BatchNormalization) (None, 27, 36, 512)  2048        conv5_1[0][0]                    
__________________________________________________________________________________________________
bn_conv5_1d (BatchNormalization (None, 27, 36, 512)  2048        conv5_1d[0][0]                   
__________________________________________________________________________________________________
relu5_1 (Activation)            (None, 27, 36, 512)  0           bn_conv5_1[0][0]                 
__________________________________________________________________________________________________
relu5_1d (Activation)           (None, 27, 36, 512)  0           bn_conv5_1d[0][0]                
__________________________________________________________________________________________________
padding5_2 (ZeroPadding2D)      (None, 29, 38, 512)  0           relu5_1[0][0]                    
__________________________________________________________________________________________________
padding5_2d (ZeroPadding2D)     (None, 29, 38, 512)  0           relu5_1d[0][0]                   
__________________________________________________________________________________________________
conv5_2 (Conv2D)                (None, 27, 36, 512)  2359808     padding5_2[0][0]                 
__________________________________________________________________________________________________
conv5_2d (Conv2D)               (None, 27, 36, 512)  2359808     padding5_2d[0][0]                
__________________________________________________________________________________________________
bn_conv5_2 (BatchNormalization) (None, 27, 36, 512)  2048        conv5_2[0][0]                    
__________________________________________________________________________________________________
bn_conv5_2d (BatchNormalization (None, 27, 36, 512)  2048        conv5_2d[0][0]                   
__________________________________________________________________________________________________
relu5_2 (Activation)            (None, 27, 36, 512)  0           bn_conv5_2[0][0]                 
__________________________________________________________________________________________________
relu5_2d (Activation)           (None, 27, 36, 512)  0           bn_conv5_2d[0][0]                
__________________________________________________________________________________________________
padding5_3 (ZeroPadding2D)      (None, 29, 38, 512)  0           relu5_2[0][0]                    
__________________________________________________________________________________________________
padding5_3d (ZeroPadding2D)     (None, 29, 38, 512)  0           relu5_2d[0][0]                   
__________________________________________________________________________________________________
conv5_3 (Conv2D)                (None, 27, 36, 512)  2359808     padding5_3[0][0]                 
__________________________________________________________________________________________________
conv5_3d (Conv2D)               (None, 27, 36, 512)  2359808     padding5_3d[0][0]                
__________________________________________________________________________________________________
bn_conv5_3 (BatchNormalization) (None, 27, 36, 512)  2048        conv5_3[0][0]                    
__________________________________________________________________________________________________
bn_conv5_3d (BatchNormalization (None, 27, 36, 512)  2048        conv5_3d[0][0]                   
__________________________________________________________________________________________________
relu5_3 (Activation)            (None, 27, 36, 512)  0           bn_conv5_3[0][0]                 
__________________________________________________________________________________________________
rois (InputLayer)               (None, 5)            0                                            
__________________________________________________________________________________________________
relu5_3d (Activation)           (None, 27, 36, 512)  0           bn_conv5_3d[0][0]                
__________________________________________________________________________________________________
rois_context (InputLayer)       (None, 5)            0                                            
__________________________________________________________________________________________________
pool5 (RoiPoolingConvSingle)    (None, 7, 7, 512)    0           relu5_3[0][0]                    
                                                                 rois[0][0]                       
__________________________________________________________________________________________________
pool5d (RoiPoolingConvSingle)   (None, 7, 7, 512)    0           relu5_3d[0][0]                   
                                                                 rois[0][0]                       
__________________________________________________________________________________________________
pool5_context (RoiPoolingConvSi (None, 7, 7, 512)    0           relu5_3[0][0]                    
                                                                 rois_context[0][0]               
__________________________________________________________________________________________________
pool5d_context (RoiPoolingConvS (None, 7, 7, 512)    0           relu5_3d[0][0]                   
                                                                 rois_context[0][0]               
__________________________________________________________________________________________________
flatten (Flatten)               (None, 25088)        0           pool5[0][0]                      
__________________________________________________________________________________________________
flatten_d (Flatten)             (None, 25088)        0           pool5d[0][0]                     
__________________________________________________________________________________________________
flatten_context (Flatten)       (None, 25088)        0           pool5_context[0][0]              
__________________________________________________________________________________________________
flatten_d_context (Flatten)     (None, 25088)        0           pool5d_context[0][0]             
__________________________________________________________________________________________________
concat (Concatenate)            (None, 100352)       0           flatten[0][0]                    
                                                                 flatten_d[0][0]                  
                                                                 flatten_context[0][0]            
                                                                 flatten_d_context[0][0]          
__________________________________________________________________________________________________
fc6 (Dense)                     (None, 4096)         411045888   concat[0][0]                     
__________________________________________________________________________________________________
drop6 (Dropout)                 (None, 4096)         0           fc6[0][0]                        
__________________________________________________________________________________________________
fc7 (Dense)                     (None, 4096)         16781312    drop6[0][0]                      
__________________________________________________________________________________________________
drop7 (Dropout)                 (None, 4096)         0           fc7[0][0]                        
__________________________________________________________________________________________________
cls_score (Dense)               (None, 20)           81940       drop7[0][0]                      
__________________________________________________________________________________________________
bbox_pred_3d (Dense)            (None, 140)          573580      drop7[0][0]                      
==================================================================================================
Total params: 457,942,816
Trainable params: 457,927,456
Non-trainable params: 15,360

模型定义的输入输出为:

tf_model = Model(
        inputs=[img, dmap, rois, rois_context],
        outputs=[cls_score, bbox_pred_3d]
    )

我在predict时采用的格式为:

    roi2d = twod_Proposal('test1_rgb.jpg', 'q') #获得roi proposal
    print('------------------------------------------')
    # for roi in roi2d:
    #     print(roi)
    # print('------------------------------------------')
    #TODO: Set input to the model
    img = cv2.imread('test1_rgb.jpg')
    dmap = cv2.imread('test1_depth.jpg')
    roi2d_context = get_roi_context(roi2d)
    tf_model = make_deng_tf_test()
    show_model_info(tf_model)
    tf_model.compile(loss='mean_squared_error', optimizer='adam', metrics=['acc'])
    [score, result_predict] = tf_model.predict([img, dmap, roi2d, roi2d_context])

报错信息为

Using TensorFlow backend.
Total Number of Region Proposals: 5012
------------------------------------------
WARNING:tensorflow:From /Users/anaconda2/envs/python3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
2019-07-01 09:51:26.089446: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2019-07-01 09:51:26.090541: I tensorflow/core/common_runtime/process_util.cc:71] Creating new thread pool with default inter op setting: 4. Tune using inter_op_parallelism_threads for best performance.
WARNING:tensorflow:From /Users/anaconda2/envs/python3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
Traceback (most recent call last):
  File "/Users/Documents/PycharmProjects/Amodal3Det_TF/tfmodel/model.py", line 375, in <module>
    [score, result_predict] = tf_model.predict([img, dmap, roi2d, roi2d_context])
  File "/Users/anaconda2/envs/python3/lib/python3.6/site-packages/keras/engine/training.py", line 1149, in predict
    x, _, _ = self._standardize_user_data(x)
  File "/Users/anaconda2/envs/python3/lib/python3.6/site-packages/keras/engine/training.py", line 751, in _standardize_user_data
    exception_prefix='input')
  File "/Users/anaconda2/envs/python3/lib/python3.6/site-packages/keras/engine/training_utils.py", line 92, in standardize_input_data
    data = [standardize_single_array(x) for x in data]
  File "/Users/anaconda2/envs/python3/lib/python3.6/site-packages/keras/engine/training_utils.py", line 92, in <listcomp>
    data = [standardize_single_array(x) for x in data]
  File "/Users/anaconda2/envs/python3/lib/python3.6/site-packages/keras/engine/training_utils.py", line 27, in standardize_single_array
    elif x.ndim == 1:
AttributeError: 'list' object has no attribute 'ndim'

Process finished with exit code 1

请问各位问题大概出在哪里?

2个回答

Please use rate instead of keep_prob. Rate should be set to rate = 1 - keep_prob.
这说得很清楚了

weixin_41727316
weixin_41727316 这个只是warning啊。问题是怎么根据网络需求设置输入格式
11 个月之前 回复

好像是keep_prob参数要修改成1-keep_prob

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐