TypeError:“方法”对象不可下标吗?

时间:2020-03-08 08:06:06

标签: python-3.x keras deep-learning prediction machine-translation

input是一个英语句子,当我运行时出现错误

代码:

  saved_weights = find_checkpoint_file('.')                                              
  print('please enter the value')                                                        
  user_input1 = input()                                                                  
  if len(saved_weights) == 0:                                                            
      print("The network hasn't been trained! Program will exit...")                     
      sys.exit()                                                                         
  else:                                                                                  
      X_test = load_test_data(user_input1, X_word_to_ix, MAX_LEN)                        
      X_test = pad_sequences(X_test, maxlen=4, dtype='int32')                            
      model.load_weights(saved_weights)                                                  
      predictions = np.argmax(model.predict[X_test])                                     
      sequences = ()                                                                     
      for prediction in predictions:                                                     
          sequence = ' '.join([y_ix_to_word[index] for index in prediction if index > 0])
          print(sequence)                                                                
          sequences.append(sequence)                                                     
      np.savetxt('test_result', sequences, fmt='%s') 

此行虽然出现错误:

      predictions = np.argmax(model.predict[X_test])  

错误:

TypeError:“方法”对象不可下标

1 个答案:

答案 0 :(得分:1)

我不确定您为什么拥有这样的代码,这是不正确的,请使用以下代码:

predictions = np.argmax(model.predict(X_test))