A
short, 34 self.data = Variable(np.array(self.data,dtype=np.float32))
Home 34 self.data = np.array(self.data,dtype=np.float32)
The following is detailed.Don’t put a line because it was hard to find it. 1 import numpy as np
2 import chainer
3 from PIL import Image
4 from chainer import cuda, Variable
5
6 class rrDataset(chainer.dataset.DatasetMixin):
7 def __init__(self,l,r,inf,outf):
8 self.rr_list = np.load('/media/denko/OS/data/rr_list/test.npy')
9 self.l = l
10 self.r = r
11 self.inf = inf
12 self.outf = outf
13 self.flames = self.inf + self.outf
14 self.num = self.r - self.l
15 self.xp = cuda.cupy
16
17 def __len__(self):
18 return self.num
19
20 def get_example(self,i):
21 self.ind = self.l + i
22 self.data = np.empty((self.flames,1,256,320),dtype=np.float32)
23
24 for j in range(self.flames):
25 self.bmp_name = str(int(self.rr_list[self.ind][j]))
26 self.year = self.bmp_name[0:4]
27 self.month = self.bmp_name[4:6]
28 self.path = '/media/denko/OS/data/bmp/' + self.year + '/' + self.month + '/' + self.bmp_name + '.bmp'
29 self.bmp_data = Image.open(self.path)
30 self.bmp_data = np.array(self.bmp_data).astype(dtype=np.float32)
31 self.bmp_data = self.bmp_data / 255
32 self.data[j,0,:,:] = self.bmp_data
33
34 self.data = Variable(np.array(self.data,dtype=np.float32))
35
36 return self.data[:self.inf,0,:,:], self.data[self.inf:self.flames,0,:,:]
The problem is that Mr. metropolis returns Varible in line 34. DatasetMixin is usually assumed to returnpp.ndarray orpp.ndarray tuples.Short code for validation. 1 from chainer.dataset.convert import concat_examples
2 from chainer import Variable
3 import numpy as np
4
5 data_np_1 = np.arange(9, dtype=np.float32).reshape((3, 3))
6 data_np_2 = data_np_1 * 2
7 data_Variable_1 = Variable(data_np_1)
8 data_Variable_2 = Variable(data_np_2)
9
10 batch_1_np = (data_np_1[:1, :], data_np_1[1:, :])
11 batch_2_np = (data_np_2[:1, :], data_np_2[1:, :])
12
13 batch_1_Variable = (data_Variable_1[:1, :], data_Variable_1[1:, :])
14 batch_2_Variable = (data_Variable_2[:1, :], data_Variable_2[1:, :])
15
16 print(concat_examples([batch_1_np, batch_2_np]))
17 print(concat_examples([batch_1_Variable, batch_2_Variable]))
18
The result is as follows. (
array([
[[0., 1., 2.]],
[[0., 2., 4.]]
], dtype=float32),
array([
[[ 3., 4., 5.], [ 6., 7., 8.]],
[[ 6., 8., 10.], [12., 14., 16.]]
], dtype=float32)
)
(
array([
[[variable(0.), variable(1.), variable(2.)]],
[[variable(0.), variable(2.), variable(4.)]]
], dtype=object),
array([
[[variable(3.), variable(4.), variable(5.)], [variable(6.), variable(7.), variable(8.)]],
[[variable(6.), variable(8.), variable(10.)], [variable(12.), variable(14.), variable(16.)]]
], dtype=object)
)
Thus, because dtype is generated ndarray,Unsupported dtype objectIt is said that.This ischainer.dataset.convert._concat_arraysCloseif not isinstance(arrays[0], numpy.ndarray) and
not isinstance(arrays[0], cuda.ndarray):
arrays = numpy.asarray(arrays)
numpy.asarray.The following is Tipps, so you can skip it.infis a reserved word representing Infinity in math.Likewise.dataThe attribute is a reserved word that represents a pointer to memory with numpy and cupy, so it is recommended not to use it yourself because it is a reserved word representing xp.ndarray in Chainer. (In fact, Chainer has been removed from the reserved word since v3.0.0 but this is because it avoided the conflict of the reserved word with numpy, cupy)