TypeError: object of type 'function' has no len()
Created by: shboy
import sys, os
import paddle.v2 as paddle
import time
from STResNet import STResNet
def main():
datadim_c = 6 * 234 * 236
datadim_p = 2 * 234 * 236
datadim_t = 2 * 234 * 236
datadim_ex = 31
resdim = 2 * 234 * 236
if len(sys.argv) == 1:
print('self def errror: input fomat error')
print('need to specify residual units')
sys.exit(-1)
else:
nb_residual_unit = int(sys.argv[1]) # number of residual units
# PaddlePaddle init
paddle.init(use_gpu=True)
input_c = paddle.layer.data(
name="input_c", type=paddle.data_type.dense_vector(datadim_c), width=234, height=236)
input_p = paddle.layer.data(
name="input_p", type=paddle.data_type.dense_vector(datadim_p), width=234, height=236)
input_t = paddle.layer.data(
name="input_t", type=paddle.data_type.dense_vector(datadim_t), width=234, height=236)
input_ex = paddle.layer.data(
name="input_ex", type=paddle.data_type.dense_vector(datadim_ex))
# Add neural network config
# option 1. resnet
main_output = STResNet(input_c, input_p, input_t, input_ex, external_dim=datadim_ex, nb_residual_unit=nb_residual_unit)
def infer_data():
def reader():
#import numpy as np
with open('/work/shenhao/test_data/event_day=2017010406070912_shuffle_test/2017010406070912', 'r') as f:
line = f.readline().strip(' ').split()
X_C = line[1: 331345]
#X_C = np.asarray(X_C)
X_P = line[331345: 331345+110448]
#X_P = np.asarray(X_P)
X_T = line[441793: 441793+110448]
#X_T = np.asarray(X_T)
X_E = line[552241: 552241+31]
#X_E = np.asarray(X_E)
return X_C, X_P, X_T, X_E
return reader
para_path = '/work/shenhao/paddle/STResNet_network_ok/params_pass_99.tar'
with open(para_path, "r") as f:
parameters = paddle.parameters.Parameters.from_tar(f)
img = paddle.infer(
output_layer=main_output,
parameters=parameters,
input=infer_data(),
feeding={'input_c': 0,
'input_p': 1,
'input_t': 2,
'input_ex': 3})
print img
if __name__ == '__main__':
ts_batch = time.time()
ts_pass = time.time()
main()