我正在写信以询问在图像分类任务中使用深度多实例学习时的错误。但是我遇到了诸如图像之类的错误,但我不知道该如何解决,有人可以教我如何解决此问题吗?谢谢!
我的图片尺寸为227 * 227 * 1,我从网站上引用了代码。
def generate_batch(path):
bags = [] for each_path in path: name_img = [] img = [] img_path = glob.glob(each_path + '/*.png') num_ins = len(img_path) label = int(each_path.split('/')[-2]) if label == 1: curr_label = np.ones(num_ins,dtype=np.uint8) else: curr_label = np.zeros(num_ins, dtype=np.uint8) for each_img in img_path: img_data = np.asarray(sci.imread(each_img), dtype=np.float32) #img_data -= 255 img_data[:, :, 0] -= 123.68 img_data[:, :, 1] -= 116.779 img_data[:, :, 2] -= 103.939 img_data /= 255 # sci.imshow(img_data) img.append(np.expand_dims(img_data,0)) name_img.append(each_img.split('/')[-1]) stack_img = np.concatenate(img, axis=0) bags.append((stack_img, curr_label, name_img)) return bags
def model_training(input_dim,数据集,irun,ifold):
train_bags = dataset['train'] test_bags = dataset['test'] # convert bag to batch train_set = generate_batch(train_bags) test_set = generate_batch(test_bags) model = Cell_Net.cell_net(input_dim, args, useMulGpu=False) # train model t1 = time.time() num_batch = len(train_set) # for epoch in range(args.max_epoch): model_name = train_eval(model, train_set, irun, ifold) print("load saved model weights") model.load_weights(model_name) test_loss, test_acc = test_eval(model, test_set) t2 = time.time() # print ('run time:', (t2 - t1) / 60.0, 'min') print ('test_acc={:.3f}'.format(test_acc)) return test_acc
如果名称 ==“ 主要”:
args = parse_args() print ('Called with args:') print (args) input_dim = (227,227,1) run = 1 n_folds = 10 acc = np.zeros((run, n_folds), dtype=float) data_path = 'C:/Users/user/Desktop/3' for irun in range(run): dataset = load_dataset(dataset_path=data_path, n_folds=n_folds, rand_state=irun) for ifold in range(n_folds): print ('run=', irun, ' fold=', ifold) acc[irun][ifold] = model_training(input_dim, dataset[ifold], irun, ifold) print ('mi-net mean accuracy = ', np.mean(acc)) print ('std = ', np.std(acc))
并显示错误: