如何解决 AttributeError: 'NoneType' 对象没有属性 'CONTENT_TYPE'

如何解决如何解决 AttributeError: 'NoneType' 对象没有属性 'CONTENT_TYPE'

我正在按照教程在 Sagemaker 上使用 MXNET 来开发推荐引擎

执行以下单元格后,我收到 AttributeError: 'nonetype' object has no attribute 'CONTENT_TYPE'

test_preds= []
for array in np.array_split(test_df[['customer_id','product_id']].values,40):
    test_preds += 
predictor.predict(json.dumps({'customer_id':array[:,0].tolist(),'product_id':array[:,1].tolist()}))
test_preds = np.array(test_preds)
print('MSE:',np.mean((test_df['star_rating'] -test_preds))**2)

显示错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-38-a830dbc6ac84> in <module>
      2 for array in np.array_split(test_df[['customer_id',40):
      3     test_preds += predictor.predict(json.dumps({'customer_id':array[:,----> 4                                    'product_id':array[:,1].tolist()}))
      5 test_preds = np.array(test_preds)
      6 print('MSE:',np.mean((test_df['star_rating'] -test_preds))**2)

~/anaconda3/envs/amazonei_mxnet_p36/lib/python3.6/site-packages/sagemaker/predictor.py in predict(self,data,initial_args,target_model,target_variant,inference_id)
    132 
    133         request_args = self._create_request_args(
--> 134             data,inference_id
    135         )
    136         response = self.sagemaker_session.sagemaker_runtime_client.invoke_endpoint(**request_args)

~/anaconda3/envs/amazonei_mxnet_p36/lib/python3.6/site-packages/sagemaker/predictor.py in _create_request_args(self,inference_id)
    158 
    159         if "ContentType" not in args:
--> 160             args["ContentType"] = self.content_type
    161 
    162         if "Accept" not in args:

~/anaconda3/envs/amazonei_mxnet_p36/lib/python3.6/site-packages/sagemaker/predictor.py in content_type(self)
    511     def content_type(self):
    512         """The MIME type of the data sent to the inference endpoint."""
--> 513         return self.serializer.CONTENT_TYPE
    514 
    515     @property

AttributeError: 'nonetype' object has no attribute 'CONTENT_TYPE'

  

**predictor 是训练模型的生产端点

test_df 在这里定义

df_titles = df[['customer_id','product_title','product_id','star_rating']]

df = df[['customer_id','star_rating']]

customers = df['customer_id'].value_counts()
products = df['product_id'].value_counts()

# Filter long-tail
customers = customers[customers >= 5]
products = products[products >= 10]
reduced_df_titles = df_titles.merge(pd.DataFrame({'customer_id': 
customers.index})).merge(pd.DataFrame({'product_id': 
products.index}))

reduced_df = df.merge(pd.DataFrame({'customer_id': 
customers.index})).merge(pd.DataFrame({'product_id': 
products.index}))
customers = reduced_df['customer_id'].value_counts()
products = reduced_df['product_id'].value_counts()

# Number users and items
#Next,we'll number each user and item,giving them their own 
sequential index. This will allow us to hold
#the information in a sparse format where the sequential indices 
indicate the row and column in our ratings matrix.
customer_index = pd.DataFrame({'customer_id': customers.index,'user': 
np.arange(customers.shape[0])})
product_index = pd.DataFrame({'product_id': products.index,'item': 
np.arange(products.shape[0])})

reduced_df = reduced_df.merge(customer_index).merge(product_index)
reduced_df_titles = 
reduced_df_titles.merge(customer_index).merge(product_index)

# Split train and test

train_df,test_df = train_test_split(reduced_df,test_size=0.2,random_state=0)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?