我正在尝试解决上面提到的错误,但我做不到。我正在尝试运行以下 python 函数:
def plot_test_samples():
fileList = os.listdir('../data/test_samples')
fileList = filter(lambda x: '.png' in x, fileList)
fileList.sort()
case_slices = [ [int(s) for s in fname.replace('.', '_').split('_') if s.isdigit()] for fname in fileList]
case_slices = np.array(case_slices)
X_test = np.load('../data/X_test.npy')
n_imgs = np.load('../data/test_n_imgs.npy').cumsum()
img_rows = X_test.shape[1]
img_cols = img_rows
model = get_model(img_rows, img_cols)
n_cols= 4
n_rows = int( np.ceil(len(case_slices)/n_cols*2) )
fig = plt.figure(figsize=[ 4*n_cols, int(4*n_rows)] )
gs = gridspec.GridSpec( n_rows , n_cols )
imgs = [ X_test[n_imgs[row[0]-1]+row[1]] for row in case_slices ]
imgs = np.stack(imgs)
masks = model.predict( imgs, verbose=1)
for mm, row in enumerate(case_slices):
ax = fig.add_subplot(gs[2*mm])
img = cv2.imread('../data/test_samples'+'/'+fileList[mm],cv2.IMREAD_COLOR)
ax.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB) )
ax = fig.add_subplot(gs[2*mm+1])
ax.imshow(imgs[mm,:,:,0], cmap='gray' )
contours = find_contours(masks[mm,:,:,0], 0.01, fully_connected='high')
for n, contour in enumerate(contours):
ax.plot(contour[:, 1], contour[:, 0], linewidth=1, color='b')
fig.savefig('../images/test_samples.png', bbox_inches='tight', dpi=300 )
len case_slices=795
shape(case_slices)=(795, 1)
len n_imgs=30
len X_test=795
shape(X_test)=(795, 256, 256, 1)
请任何人知道我如何解决这个问题让我知道,提前谢谢