def resBlock(preAct, resParams, train, bn_updates, BA, GAselect): snrg = RandomStreams(12345) current_params = resParams[0] inAct, newRM, newRV = layers.convBNAct(preAct, current_params[:6], train) bn_updates.append((current_params[4], newRM)) bn_updates.append((current_params[5], newRV)) inAct = STEquant(inAct, BA) if GAselect == 2: inAct = quantizeGrad.quantizeGradL2(inAct) elif GAselect == 4: inAct = quantizeGrad.quantizeGradL4(inAct) elif GAselect == 6: inAct = quantizeGrad.quantizeGradL6(inAct) elif GAselect == 10: inAct = quantizeGrad.quantizeGradL10(inAct) elif GAselect == 12: inAct = quantizeGrad.quantizeGradL12(inAct) elif GAselect == 16: inAct = quantizeGrad.quantizeGradL16(inAct) elif GAselect == 18: inAct = quantizeGrad.quantizeGradL18(inAct) inAct = layers.dropout(inAct, train, 0.8, snrg) current_params = resParams[1] outAct, newRM, newRV = layers.convBN(inAct, current_params[:6], train) bn_updates.append((current_params[4], newRM)) bn_updates.append((current_params[5], newRV)) outAct = layers.slopedClipping(outAct + preAct) return outAct, bn_updates
def resBlockStride(preAct, resParams, train, bn_updates, BA, GAselect): snrg = RandomStreams(12345) current_params = resParams[0] inAct, newRM, newRV = layers.convStrideBNAct(preAct, current_params[:6], train) bn_updates.append((current_params[4], newRM)) bn_updates.append((current_params[5], newRV)) inAct = STEquant(inAct, BA) if GAselect == 8: inAct = quantizeGrad.quantizeGradL8(inAct) elif GAselect == 14: inAct = quantizeGrad.quantizeGradL14(inAct) inAct = layers.dropout(inAct, train, 0.8, snrg) current_params = resParams[1] outAct, newRM, newRV = layers.convBN(inAct, current_params[:6], train) bn_updates.append((current_params[4], newRM)) bn_updates.append((current_params[5], newRV)) current_params = resParams[2] shortCut, newRM, newRV = layers.convStrideBN(preAct, current_params[:6], train) bn_updates.append((current_params[4], newRM)) bn_updates.append((current_params[5], newRV)) outAct = layers.slopedClipping(outAct + shortCut) return outAct, bn_updates
def resBlock(preAct, resParams, train): resActivations = [] current_params = resParams[0] inAct, _, _ = layers.convBNAct(preAct, current_params, train) resActivations.append(inAct) current_params = resParams[1] outAct, _, _ = layers.convBN(inAct, current_params, train) outAct = layers.slopedClipping(outAct + preAct) resActivations.append(outAct) return outAct, resActivations
def resBlock(preAct, resParams, train, BA1, BA2, BW1, BW2): current_params = resParams[0] current_params[0] = layers.quantizeWeight(current_params[0], BW1) inAct, _, _ = layers.convBNAct(preAct, current_params, train) inAct = layers.quantizeAct(inAct, BA1) inAct = 0.8 * inAct current_params = resParams[1] current_params[0] = layers.quantizeWeight(current_params[0], BW2) outAct, _, _ = layers.convBN(inAct, current_params, train) outAct = layers.slopedClipping(outAct + preAct) outAct = layers.quantizeAct(outAct, BA2) return outAct
def resBlockStride(preAct, resParams, train, BA1, BA2, BW1, BW2, BW3): current_params = resParams[0] current_params[0] = layers.quantizeWeight(current_params[0], BW1) inAct, _, _ = layers.convStrideBNAct(preAct, current_params, train) inAct = 0.8 * inAct current_params = resParams[1] current_params[0] = layers.quantizeWeight(current_params[0], BW2) outAct, _, _ = layers.convBN(inAct, current_params, train) current_params = resParams[2] current_params[0] = layers.quantizeWeight(current_params[0], BW3) shortCut, _, _ = layers.convStrideBN(preAct, current_params, train) outAct = layers.slopedClipping(outAct + shortCut) return outAct
def resBlockStride(preAct, resParams, train): resActivations = [] current_params = resParams[0] inAct, _, _ = layers.convStrideBNAct(preAct, current_params, train) resActivations.append(inAct) inAct = 0.8 * inAct current_params = resParams[1] outAct, _, _ = layers.convBN(inAct, current_params, train) current_params = resParams[2] shortCut, _, _ = layers.convStrideBN(preAct, current_params, train) outAct = layers.slopedClipping(outAct + shortCut) resActivations.append(outAct) return outAct, resActivations
def resBlock(preAct, resParams, train, bn_updates): snrg = RandomStreams(12345) resActivations = [] current_params = resParams[0] inAct, newRM, newRV = layers.convBNAct(preAct, current_params, train) resActivations.append(inAct) bn_updates.append((current_params[4], newRM)) bn_updates.append((current_params[5], newRV)) inAct = layers.dropout(inAct, train, 0.8, snrg) current_params = resParams[1] outAct, newRM, newRV = layers.convBN(inAct, current_params, train) bn_updates.append((current_params[4], newRM)) bn_updates.append((current_params[5], newRV)) outAct = layers.slopedClipping(outAct + preAct) resActivations.append(outAct) return outAct, resActivations, bn_updates