microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.49k stars 4.29k forks source link

Train Feature Dimension and Write Feature Dimension must be equal? #838

Closed Martlgap closed 7 years ago

Martlgap commented 7 years ago

Hey Guys, I couldn´t find anything about my concern, so I decided to just add a new issue.

I have a Network with 3 Convolutional Layers trained with Images (33x33x3). The Network makes a HighResolution Image out of a LowResolution Image. I changed the CTNK code, to enable reading an Image as a Label. (Everything is working)

Now I would like to perform the Write-Action with Images of different Dimensions i.e.(480x500x3). Is that in general possible? Another question which came up, why do I need to enter the label-part inside the reader inside the write-action inside the config file? I thought the write action just needs information about the features, not about the labels?

When I try to run it, the following error appears: EXCEPTION occurred: NotifyFunctionValuesMBSizeModified: features InputValue operation had its row dimension 3267 changed by the reader to 720000.

Any Suggestion or Comments?

Thanks for your help, Martin

frankseide commented 7 years ago

You can use an edit operation to replace your Input node with one that matches the new size. That will get you to the top of the image-processing "pyramid", but then your spatial extend will not match the dense layer, and since that layer is trained, it cannot process the other size.

We will soon have a variant of Pooling (ROIPooling) which uses adaptive non-integer strides. That may allow what you need.

Martlgap commented 7 years ago

Thank you very much for your quick reply. I just use convolutions and relu units, so I think I don´t have dense layers, so the edit operation should work in my case am I right?

Unfortunately I am not able to figure out how to use the Edit Operator in my case. My plan is to write a new config with a train and write action. In the train action I have a first proposal:

Train=[ action="train" modelPath="$ModelDir$/SuperResolutionPaperNetwork_V5" BrainScriptNetworkBuilder = [ old_network = BS.Network.Load("$ModelDir$/SuperResolutionPaperNetwork_V5") new_network = BS.Network.Edit( old_network.input, parameters="constant")

    imageW = 480
    imageH = 500
    imageC = 3

    input = ImageInput(imageW, imageH, imageC, imageLayout="cudnn")

    features = new_network(input)
]

It´s not working, can you help me on that?

best regards, Martin

pkranen commented 7 years ago

Hi Martin,

you can look at the branch pkranen/fast-rcnn for an example here: https://github.com/Microsoft/CNTK/blob/pkranen/fast-rcnn/Examples/Image/Detection/FastRCNN/fastrcnn.cntk. In that example the test action uses a different size for ROIs and labels, but you can do the same for features. Here is a snippet:

    BrainScriptNetworkBuilder = { 
         imageShape = $ImageH$:$ImageW$:$ImageC$        # 1000:1000:3 
         labelShape = $NumLabels$:$NumTestROIs$         # 21:200 
         ROIShape   = 4:$NumTestROIs$                   # 4:200 

         # load network 
         network = BS.Network.Load ("$modelPath$") 
         clonedNet = BS.Network.CloneFunction ((network.features:network.rois), { z = network.z }, parameters="constant") 

         features = Input (imageShape) 
         roiLabels = Input (labelShape) 
         rois = Input (ROIShape) 

         z = clonedNet(features, rois).z 
Martlgap commented 7 years ago

Thank you! I ll try it when I have time and report if it works :)

Martlgap commented 7 years ago

Hi, I don´t get it work. I think I can use in my case the Edit() Function, but I cannot find any documentary about the use of that function. I don´t know what editFunctions and additionalRoots are in that case? Can anybody provide some more details about that?

Best regards, Martin