我正在使用以下代码将numpy阵列转换为张量:
self.transform_1 = transforms.Compose([transforms.ToTensor()])
source_parsing_np = cv2.imread(source_parsing_path, cv2.IMREAD_GRAYSCALE) #The range is integer in the range [0,14]
source_parsing_tensor = self.transform_1(source_parsing_tensor)
as 文档说,数据将缩放到[0.0,1.0]。但是在我的环境中,不同的时间出现了两个不同的结果。
具体来说,在以前的培训和测试代码以及我现在正在测试的Jupyter笔记本电脑代码中,张量结果仍在整个范围内[0,14]。 错误的范围结果
当我再次在测试阶段使用相同的代码时,数据真正缩放到[0.0,1.0],与以前的火车阶段不同。另一个具有相同转换的Numpy数组数据尚未更改([0,24]中的整数)。 相同的变换不同的结果
由于上述问题,我无法再现模型测试结果。我将非常感谢有关此信息的任何信息。
I am converting the numpy array to tensor with the following code:
self.transform_1 = transforms.Compose([transforms.ToTensor()])
source_parsing_np = cv2.imread(source_parsing_path, cv2.IMREAD_GRAYSCALE) #The range is integer in the range [0,14]
source_parsing_tensor = self.transform_1(source_parsing_tensor)
As the documentation says, the data will be scaled to [0.0, 1.0]. But in my environment, two different results appeared at different times.
Specifically, in the previous training and testing code and the jupyter notebook code I'm testing now, the tensor results are still integer in the range [0,14]. wrong range result
When I use the same code in test phase again, the data truly be scaled to [0.0, 1.0], which is different from previous train phase. And another numpy array data is with same transform has not been changed(still integer in [0,24]). same transform different result
Because of the above problem I cannot reproduce my model test results. I would be very thankful for any information on this.
发布评论
评论(1)
我发现原因是:仅当numpy.ndarray的dtype = np.uint8时,转换才会发生,但是我的dytpe是np. long,对我的粗心感到抱歉。
I found the reason: the conversion occurs only when the numpy.ndarray has dtype = np.uint8, but my dytpe is np.long, sorry for my carelessness.