-
I am trying to adapt the So my questions are:
TIA |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
I have come up with a solution and am recording here in case it is useful for someone else. And I am still unsure that this is the way to do it. The protected Pipeline pipeline;
protected Pipeline targetPipeline; which are set by: public T optPipeline(Pipeline pipeline)
public T optTargetPipeline(Pipeline targetPipeline) We can set the AEMnist mnist =
AEMnist.builder()
.optUsage(usage)
.setSampling(batchSize, randomize)
.optLimit( maxBatches)
.optTargetPipeline( Pipeline(new ToTensor()) )
.build()
DataIterable iter = mnist.getData from the private Batch fetch(List<Long> indices, int progress) throws IOException that checks if any pipeline with one or more transforms exists. If they do exist, then the Note that So now that leaves me with one more issue: how to replace the current numeric labels with the original image? What I did was copy and paste Assign the data to the labels so: //labels = new NDArray[] {readLabel(labelItem)};
aelabels = new NDArray[] {readIntLabel(labelItem)};
data = new NDArray[] {readData(imageItem, aelabels[0].size())};
labels = data;
prepared = true; and then hijacked the private NDArray readLabel(Artifact.Item item) throws IOException {
return readData(item, aelabels[0].size());
}
private NDArray readIntLabel(Artifact.Item item) throws IOException {
try (InputStream is = resource.getRepository().openStream(item, null)) {
if (is.skip(8) != 8) {
throw new AssertionError("Failed skip data.");
}
byte[] buf = Utils.toByteArray(is);
try (NDArray array = manager.create(new Shape(buf.length), DataType.UINT8)) {
array.set(buf);
return array.toType(DataType.FLOAT32, false);
}
}
} Now, I looked at the underlying logic, which is quite complex, and am thinking that:
Can anyone tell me if the changes I made are ok (point (2) above)? TIA |
Beta Was this translation helpful? Give feedback.
-
@zachgk Cannot seem to mark your reply as an answer. If you copy your reply as an "answer", I will tag it as the answer. Sorry. |
Beta Was this translation helpful? Give feedback.
-
I mentioned another option for how you could create an Mnist variant in #601 (reply in thread), but this should also work fine. For the normalization, you really just need a division by 255. So, you can add that as a transform like you are thinking with new Pipeline().addTransform(a -> a.div(255f)).addTransform(new ToTensor()). You can also add a LambdaBlock to your model as well, but I think the transform is a slightly nicer approach. |
Beta Was this translation helpful? Give feedback.
I mentioned another option for how you could create an Mnist variant in #601 (reply in thread), but this should also work fine.
For the normalization, you really just need a division by 255. So, you can add that as a transform like you are thinking with new Pipeline().addTransform(a -> a.div(255f)).addTransform(new ToTensor()). You can also add a LambdaBlock to your model as well, but I think the transform is a slightly nicer approach.