>

2 스트림 컨볼 루션 인 TwoStream-IQA 에 대한 교육 코드를 작성 중입니다. 신경망. 이 모델은 두 개의 네트워크 스트림을 통해 평가되는 패치의 품질 점수를 예측합니다. 아래 교육에서는 위의 GitHub 링크에 제공된 테스트 데이터 세트를 사용했습니다.

교육 코드는 다음과 같습니다.

## prepare training data 
test_label_path = 'data_list/test.txt'
test_img_path = 'data/live/'
test_Graimg_path = 'data/live_grad/'
save_model_path = '/models/nr_sana_2stream.model'
patches_per_img = 256
patchSize = 32
print('-------------Load data-------------')
final_train_set = []
with open(test_label_path, 'rt') as f:
    for l in f:
        line, la = l.strip().split()  # for debug
        tic = time.time()
        full_path = os.path.join(test_img_path, line)
        Grafull_path = os.path.join(test_Graimg_path, line)
        f = Image.open(full_path)
        Graf = Image.open(Grafull_path)
        img = np.asarray(f, dtype=np.float32)
        Gra = np.asarray(Graf, dtype=np.float32)
        img = img.transpose(2, 0, 1)
        Gra = Gra.transpose(2, 0, 1)
        img1 = np.zeros((1, 3, Gra.shape[1], Gra.shape[2]))
        img1[0, :, :, :] = img
        Gra1 = np.zeros((1, 3, Gra.shape[1], Gra.shape[2]))
        Gra1[0, :, :, :] = Gra
        patches = extract_patches(img, (3, patchSize, patchSize), patchSize)
        Grapatches = extract_patches(Gra, (3, patchSize, patchSize), patchSize)
        X = patches.reshape((-1, 3, patchSize, patchSize))
        GraX = Grapatches.reshape((-1, 3, patchSize, patchSize))
        temp_slice1 = [X[int(float(index))] for index in range(256)]
        temp_slice2 = [GraX[int(float(index))] for index in range(256)]
        ##############################################  
        for j in range(len(temp_slice1)):
            temp_slice1[j] = xp.array(temp_slice1[j].astype(np.float32))
            temp_slice2[j] = xp.array(temp_slice2[j].astype(np.float32))
            final_train_set.append((temp_slice1[j], temp_slice2[j], int(la)))
    final_train_set = np.asarray(final_train_set)       
        ##############################################  
#
print('--------------Done!----------------')
print('--------------Iterator!----------------')    
train_iter = iterators.SerialIterator(final_train_set, batch_size=4)
optimizer = optimizers.Adam()
optimizer.use_cleargrads()
optimizer.setup(model)
updater = training.StandardUpdater(train_iter, optimizer, device=0)
print('--------------Trainer!----------------') 
trainer = training.Trainer(updater, (50, 'epoch'), out='result')
trainer.extend(extensions.LogReport())
trainer.extend(extensions.PrintReport(['epoch', 'iteration', 'main/loss', 'elapsed_time']))
print('--------------Running trainer!----------------') 
trainer.run()

그러나 코드는 다음과 같이 오류를 생성합니다.

Exception in main training loop: Unsupported dtype object
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/chainer/training/trainer.py", line 307, in run
    update()
  File "/usr/local/lib/python2.7/dist-packages/chainer/training/updaters/standard_updater.py", line 165, in update
    self.update_core()
  File "/usr/local/lib/python2.7/dist-packages/chainer/training/updaters/standard_updater.py", line 171, in update_core
    in_arrays = self.converter(batch, self.device)
  File "/usr/local/lib/python2.7/dist-packages/chainer/dataset/convert.py", line 149, in concat_examples
    return to_device(device, _concat_arrays(batch, padding))
  File "/usr/local/lib/python2.7/dist-packages/chainer/dataset/convert.py", line 37, in to_device
    return cuda.to_gpu(x, device)
  File "/usr/local/lib/python2.7/dist-packages/chainer/backends/cuda.py", line 288, in to_gpu
    return _array_to_gpu(array, device_, stream)
  File "/usr/local/lib/python2.7/dist-packages/chainer/backends/cuda.py", line 336, in _array_to_gpu
    return cupy.asarray(array)
  File "/usr/local/lib/python2.7/dist-packages/cupy/creation/from_data.py", line 60, in asarray
    return core.array(a, dtype, False)
  File "cupy/core/core.pyx", line 2174, in cupy.core.core.array
  File "cupy/core/core.pyx", line 2207, in cupy.core.core.array
Will finalize trainer extensions and updater before reraising the exception.
Traceback (most recent call last):
  File "train.py", line 126, in <module>
    trainer.run()
  File "/usr/local/lib/python2.7/dist-packages/chainer/training/trainer.py", line 321, in run
    six.reraise(*sys.exc_info())
  File "/usr/local/lib/python2.7/dist-packages/chainer/training/trainer.py", line 307, in run
    update()
  File "/usr/local/lib/python2.7/dist-packages/chainer/training/updaters/standard_updater.py", line 165, in update
    self.update_core()
  File "/usr/local/lib/python2.7/dist-packages/chainer/training/updaters/standard_updater.py", line 171, in update_core
    in_arrays = self.converter(batch, self.device)
  File "/usr/local/lib/python2.7/dist-packages/chainer/dataset/convert.py", line 149, in concat_examples
    return to_device(device, _concat_arrays(batch, padding))
  File "/usr/local/lib/python2.7/dist-packages/chainer/dataset/convert.py", line 37, in to_device
    return cuda.to_gpu(x, device)
  File "/usr/local/lib/python2.7/dist-packages/chainer/backends/cuda.py", line 288, in to_gpu
    return _array_to_gpu(array, device_, stream)
  File "/usr/local/lib/python2.7/dist-packages/chainer/backends/cuda.py", line 336, in _array_to_gpu
    return cupy.asarray(array)
  File "/usr/local/lib/python2.7/dist-packages/cupy/creation/from_data.py", line 60, in asarray
    return core.array(a, dtype, False)
  File "cupy/core/core.pyx", line 2174, in cupy.core.core.array
  File "cupy/core/core.pyx", line 2207, in cupy.core.core.array
ValueError: Unsupported dtype object

위에 제공된 github 링크의 데이터 세트를 사용했습니다. 저는 Chainer의 초보자입니다. 도와주세요 !!


  • 답변 # 1

    final_train_set.append((temp_slice1[j], temp_slice2[j], int(la)))
    
    

    이것은 final_train_set 를 만듭니다  혼합 유형의 튜플 목록 ( numpy.ndarray )  그리고 int ). 따라서 np.asarray(final_train_set)   dtype = numpy.object 의 결과 을 지원하지 않는 Chainer입니다.

    SerialIterator 에 전달하기 위해 올바른 방법은

    # list of tuples of data and labels
    final_train_set.append((
        numpy.asarray((temp_slice1[j], temp_slice2[j])).astype(numpy.float32),
        int(la)
    ))
    
    
    루프 후

    아무것도하지 않습니다.

  • 답변 # 2

    오류가 발생합니다

    와이즈 비즈

    카이 너는

    ValueError: Unsupported dtype object

    를 지원합니다  그리고 numpy.float32  정렬. 데이터 배열 cupy.float32 변환은 어떻습니까?  다음과 같이?

    dtype
    
    
    final_train_set = np.asarray(final_train_set).astype(np.float32)

관련 자료

  • 이전 java - Sonar-Use-with-resources 또는 "finally"절 java8 stream에서이 "Stream"을 닫으십시오
  • 다음 java - 어떤 하위 클래스가 수퍼 클래스를 호출하는지 알 수있는 방법이 있습니까?