【发布时间】:2019-06-03 05:38:43
【问题描述】:
我需要一个仅包含图像的数据集对象,用于在 Chainer 框架中进行无监督学习。为此,我正在尝试使用 DatasetMixin。
Images 是一个包含图像的列表。
class SimpleDataset(dataset.DatasetMixin):
def __init__(self, Images):
self.Images = Images
def __len__(self):
return len(self.Images)
def get_example(self, i):
return self.Images[i]
SimpleDataset 类似乎无法读取图像,因为在运行 trainer.run() 时出现错误:
call() missing 1 required positional argument: 'x'
在将图像列表放入 DatasetMixin 类之前,我是否需要进一步处理它?
使用 DatasetMixin 以这种方式只提供图像有什么问题吗?
我可以做些什么来只为我的模型提供图像(没有任何标签或其他东西)?
class AutoEncoder(chainer.Chain):
def __init__(self, n_in, n_out):
super(AutoEncoder, self).__init__(
l1 = L.Linear(n_in, n_out),
l2 = L.Linear(n_out, n_in)
)
self.add_param('decoder_bias', n_in)
self.decoder_bias.data[...] = 0
def __call__(self, x):
h1 = F.dropout(self.l1(x))
h2 = F.linear(h1, F.transpose(self.l1.W), self.decoder_bias)
return F.sigmoid(h2)
def encode(self, x):
return F.dropout(self.l1(x))
def decode(self, x):
return self.l2(x)
model = L.Classifier(AutoEncoder(40000, 1000), lossfun=F.mean_squared_error)
model.compute_accuracy = False
【问题讨论】:
-
你能分享你的模型定义吗?您是否使用了
Classifier或一些包装模型?数据集定义本身看起来不错。 -
嗨@corochann,我已经编辑了问题以添加模型定义。
-
由于我使用了分类器,所以我尝试使用 model = AutoEncoder(x, y)。在这种情况下,错误是 AttributeError: 'NoneType' object has no attribute 'dtype'
标签: unsupervised-learning chainer imagedata