public void CancelSelection() { switch (curChar) { case SelectableCharacters.Leslie: CD.GetComponent <Collider2D>().isTrigger = true; Leslie.GetComponent <Image>().sprite = HoverImages[0]; break; case SelectableCharacters.Jona: ND.GetComponent <Collider2D>().isTrigger = true; Jona.GetComponent <Image>().sprite = HoverImages[1]; break; case SelectableCharacters.Ashita: NED.GetComponent <Collider2D>().isTrigger = true; Ashita.GetComponent <Image>().sprite = HoverImages[2]; break; case SelectableCharacters.Catarine: ED.GetComponent <Collider2D>().isTrigger = true; Catarine.GetComponent <Image>().sprite = HoverImages[3]; break; case SelectableCharacters.Ramsey: SED.GetComponent <Collider2D>().isTrigger = true; Ramsey.GetComponent <Image>().sprite = HoverImages[4]; break; case SelectableCharacters.Drogas: SD.GetComponent <Collider2D>().isTrigger = true; Drogas.GetComponent <Image>().sprite = HoverImages[5]; break; case SelectableCharacters.Sylvia: SWD.GetComponent <Collider2D>().isTrigger = true; Sylvia.GetComponent <Image>().sprite = HoverImages[6]; break; case SelectableCharacters.Bjin: WD.GetComponent <Collider2D>().isTrigger = true; Bjin.GetComponent <Image>().sprite = HoverImages[7]; break; case SelectableCharacters.Xavier: NWD.GetComponent <Collider2D>().isTrigger = true; Xavier.GetComponent <Image>().sprite = HoverImages[8]; break; case SelectableCharacters.None: break; default: break; } weaponSelect.SetActive(false); weaponSelectActive = false; characterChosen = false; }
internal WeightInitialisationProvider(ILinearAlgebraProvider lap) { Ones = new Constant(lap, 0f, 1f); Zeroes = new Constant(lap, 0f, 0f); Gaussian = new Gaussian(lap); Xavier = new Xavier(lap); Identity = new Identity(lap, 1f); Identity01 = new Identity(lap, 0.1f); }
public void makeAllDissapear() { Leslie.SetActive(false); Jona.SetActive(false); Ashita.SetActive(false); Catarine.SetActive(false); Ramsey.SetActive(false); Drogas.SetActive(false); Sylvia.SetActive(false); Bjin.SetActive(false); Xavier.SetActive(false); }
public FeatureExpander(string network, string[] outputs, int[] num_filters, bool use_1x1_transition = true, bool use_bn = true, float reduce_ratio = 1, int min_depth = 128, bool global_pool = false, bool pretrained = false, Context ctx = null, string[] inputs = null, ParameterDict @params = null) : base(null, null, @params) { var(p_i, p_o, p_p) = __internal__.ParseNetwork(network, outputs, inputs, pretrained, ctx); // append more layers var y = p_o.Last(); var weight_init = new Xavier(rnd_type: "gaussian", factor_type: "out", magnitude: 2); foreach (var _tup_2 in num_filters.Select((_p_1, _p_2) => Tuple.Create(_p_2, _p_1))) { var i = _tup_2.Item1; var f = _tup_2.Item2; if (use_1x1_transition) { var num_trans = Math.Max(min_depth, Convert.ToInt32(Math.Round(f * reduce_ratio))); y = sym.Convolution(y, weight_init.InitWeight("weight"), null, num_filter: num_trans, kernel: new Shape(1, 1), no_bias: use_bn, symbol_name: $"expand_trans_conv{i}"); if (use_bn) { y = sym.BatchNorm(y, null, null, null, null, symbol_name: $"expand_trans_bn{i}"); } y = sym.Activation(y, act_type: ActivationType.Relu, symbol_name: $"expand_trans_relu{i}"); } y = sym.Convolution(y, weight_init.InitWeight("weight"), null, num_filter: f, kernel: new Shape(3, 3), pad: new Shape(1, 1), stride: new Shape(2, 2), no_bias: use_bn, symbol_name: $"expand_conv{i}"); if (use_bn) { y = sym.BatchNorm(y, null, null, null, null, symbol_name: $"expand_bn{i}"); } y = sym.Activation(y, act_type: ActivationType.Relu, symbol_name: $"expand_reu{i}"); p_o.Add(y); } if (global_pool) { p_o.Add(sym.Pooling(y, pool_type: PoolingType.Avg, global_pool: true, kernel: new Shape(1, 1))); } base.Construct(p_o, p_i, p_p); }
private static void Main() { /*basic config*/ const int batchSize = 256; const int maxEpo = 100; const float learningRate = 1e-4f; const float weightDecay = 1e-4f; /*context and net symbol*/ var ctx = Context.Gpu(); var net = AlexnetSymbol(2); /*args_map and aux_map is used for parameters' saving*/ var argsMap = new Dictionary <string, NDArray>(); var auxMap = new Dictionary <string, NDArray>(); /*we should tell mxnet the shape of data and label*/ argsMap["data"] = new NDArray(new Shape(batchSize, 3, 256, 256), ctx); argsMap["label"] = new NDArray(new Shape(batchSize), ctx); /*with data and label, executor can be generated varmatically*/ using (var exec = net.SimpleBind(ctx, argsMap)) { var argNames = net.ListArguments(); var auxiliaryDictionary = exec.AuxiliaryDictionary(); var argmentDictionary = exec.ArgmentDictionary(); /*if fine tune from some pre-trained model, we should load the parameters*/ // NDArray.Load("./model/alex_params_3", nullptr, &args_map); /*else, we should use initializer Xavier to init the params*/ var xavier = new Xavier(RandType.Gaussian, FactorType.In, 2.34f); foreach (var arg in argmentDictionary) { /*be careful here, the arg's name must has some specific ends or starts for * initializer to call*/ xavier.Operator(arg.Key, arg.Value); } /*print out to check the shape of the net*/ foreach (var s in net.ListArguments()) { Logging.LG(s); var sb = new StringBuilder(); var k = argmentDictionary[s].GetShape(); foreach (var i in k) { sb.Append($"{i} "); } Logging.LG(sb.ToString()); } /*these binary files should be generated using im2rc tools, which can be found * in mxnet/bin*/ var trainIter = new MXDataIter("ImageRecordIter") .SetParam("path_imglist", "./data/train.lst") .SetParam("path_imgrec", "./data/train.rec") .SetParam("data_shape", new Shape(3, 256, 256)) .SetParam("batch_size", batchSize) .SetParam("shuffle", 1) .CreateDataIter(); var valIter = new MXDataIter("ImageRecordIter") .SetParam("path_imglist", "./data/val.lst") .SetParam("path_imgrec", "./data/val.rec") .SetParam("data_shape", new Shape(3, 256, 256)) .SetParam("batch_size", batchSize) .CreateDataIter(); var opt = OptimizerRegistry.Find("ccsgd"); opt.SetParam("momentum", 0.9) .SetParam("rescale_grad", 1.0 / batchSize) .SetParam("clip_gradient", 10) .SetParam("lr", learningRate) .SetParam("wd", weightDecay); var accuracyTrain = new Accuracy(); var accuracyVal = new Accuracy(); var loglossVal = new LogLoss(); for (var iter = 0; iter < maxEpo; ++iter) { Logging.LG($"Train Epoch: {iter}"); /*reset the metric every epoch*/ accuracyTrain.Reset(); /*reset the data iter every epoch*/ trainIter.Reset(); while (trainIter.Next()) { var batch = trainIter.GetDataBatch(); Logging.LG($"{trainIter.GetDataBatch().Index.Length}"); /*use copyto to feed new data and label to the executor*/ batch.Data.CopyTo(argmentDictionary["data"]); batch.Label.CopyTo(argmentDictionary["label"]); exec.Forward(true); exec.Backward(); for (var i = 0; i < argNames.Count; ++i) { if (argNames[i] == "data" || argNames[i] == "label") { continue; } opt.Update(i, exec.ArgmentArrays[i], exec.GradientArrays[i]); } NDArray.WaitAll(); accuracyTrain.Update(batch.Label, exec.Outputs[0]); } Logging.LG($"ITER: {iter} Train Accuracy: {accuracyTrain.Get()}"); Logging.LG($"Val Epoch: {iter}"); accuracyVal.Reset(); valIter.Reset(); loglossVal.Reset(); while (valIter.Next()) { var batch = valIter.GetDataBatch(); Logging.LG($"{valIter.GetDataBatch().Index.Length}"); batch.Data.CopyTo(argmentDictionary["data"]); batch.Label.CopyTo(argmentDictionary["label"]); exec.Forward(false); NDArray.WaitAll(); accuracyVal.Update(batch.Label, exec.Outputs[0]); loglossVal.Update(batch.Label, exec.Outputs[0]); } Logging.LG($"ITER: {iter} Val Accuracy: {accuracyVal.Get()}"); Logging.LG($"ITER: {iter} Val LogLoss: {loglossVal.Get()}"); /*save the parameters*/ var savePathParam = $"./model/alex_param_{iter}"; var saveArgs = argmentDictionary; /*we do not want to save the data and label*/ if (saveArgs.ContainsKey("data")) { saveArgs.Remove("data"); } if (saveArgs.ContainsKey("label")) { saveArgs.Remove("label"); } /*the alexnet does not get any aux array, so we do not need to save * aux_map*/ Logging.LG($"ITER: {iter} Saving to...{savePathParam}"); NDArray.Save(savePathParam, saveArgs); } /*don't foget to release the executor*/ } MXNet.MXNotifyShutdown(); }
private void Construct(SymbolList outputs, SymbolList inputs, ParameterDict @params, int[] num_filters, bool use_1x1 = true, bool use_upsample = true, bool use_elewadd = true, bool use_p6 = false, bool p6_conv = true, bool no_bias = true, bool pretrained = false, string norm_layer = null, FuncArgs norm_kwargs = null, Context ctx = null) { Symbol y_p6 = null; // e.g. For ResNet50, the feature is : // outputs = ['stage1_activation2', 'stage2_activation3', // 'stage3_activation5', 'stage4_activation2'] // with regard to [conv2, conv3, conv4, conv5] -> [C2, C3, C4, C5] // append more layers with reversed order : [P5, P4, P3, P2] var y = outputs.Last(); var base_features = outputs.Take(outputs.Length - 1).ToArray(); var num_stages = num_filters.Length + 1; var weight_init = new Xavier(rnd_type: "uniform", factor_type: "in", magnitude: 1); var tmp_outputs = new List <Symbol>(); // num_filter is 256 in ori paper for (int i = 0; i < base_features.Length; i++) { var bf = base_features[i]; var f = num_filters[i]; if (i == 0) { if (use_1x1) { y = sym.Convolution(y, weight_init.InitWeight("weight"), null, num_filter: f, kernel: new Shape(1, 1), pad: new Shape(0, 0), stride: new Shape(1, 1), no_bias: no_bias, symbol_name: $"P{num_stages - i}_conv_lat"); if (norm_layer != null) { if (norm_layer == "SyncBatchNorm") { norm_kwargs["key"] = $"P{num_stages - i}_lat_bn"; norm_kwargs["name"] = $"P{num_stages - i}_lat_bn"; } var bn = LayerUtils.NormLayer(norm_layer, norm_kwargs); y = bn.Call(y); } } if (use_p6 && p6_conv) { // method 2 : use conv (Deformable use this) y_p6 = sym.Convolution(y, weight_init.InitWeight("weight"), null, num_filter: f, kernel: new Shape(3, 3), pad: new Shape(1, 1), stride: new Shape(2, 2), no_bias: no_bias, symbol_name: $"P{num_stages + 1}_conv1"); if (norm_layer != null) { if (norm_layer == "SyncBatchNorm") { norm_kwargs["key"] = $"P{num_stages - i}_pre_bn"; norm_kwargs["name"] = $"P{num_stages - i}_pre_bn"; } var bn = LayerUtils.NormLayer(norm_layer, norm_kwargs); y_p6 = bn.Call(y_p6); } } } else { if (use_1x1) { bf = sym.Convolution(bf, weight_init.InitWeight("weight"), null, num_filter: f, kernel: new Shape(1, 1), pad: new Shape(0, 0), stride: new Shape(1, 1), no_bias: no_bias, symbol_name: $"P{num_stages - i}_conv_lat"); if (norm_layer != null) { if (norm_layer == "SyncBatchNorm") { norm_kwargs["key"] = $"P{num_stages - i}_conv1_bn"; norm_kwargs["name"] = $"P{num_stages - i}_conv1_bn"; } var bn = LayerUtils.NormLayer(norm_layer, norm_kwargs); bf = bn.Call(bf); } } if (use_upsample) { y = sym.UpSampling(y, scale: 2, num_args: 1, sample_type: UpsamplingSampleType.Nearest, symbol_name: $"P{num_stages - i}_upsp"); } if (use_elewadd) { // make two symbol alignment // method 1 : mx.sym.Crop // y = mx.sym.Crop(*[y, bf], name="P{}_clip".format(num_stages-i)) // method 2 : mx.sym.slice_like y = sym.SliceLike(y, bf, axes: new Shape(2, 3), symbol_name: $"P{num_stages - i}_clip"); y = sym.ElemwiseAdd(bf, y, symbol_name: $"P{num_stages - i}_sum"); } } // Reduce the aliasing effect of upsampling described in ori paper var @out = sym.Convolution(y, weight_init.InitWeight("weight"), null, num_filter: f, kernel: new Shape(3, 3), pad: new Shape(1, 1), stride: new Shape(1, 1), no_bias: no_bias, symbol_name: $"P{num_stages - i}_conv1"); if (i == 0 && use_p6 && !p6_conv) { // method 2 : use max pool (Detectron use this) y_p6 = sym.Pooling(@out, pool_type: PoolingType.Max, kernel: new Shape(1, 1), pad: new Shape(0, 0), stride: new Shape(2, 2), symbol_name: $"P{num_stages + 1}_pre"); } if (norm_layer != null) { if (norm_layer == "SyncBatchNorm") { norm_kwargs["key"] = $"P{num_stages - i}_bn"; norm_kwargs["name"] = $"P{num_stages - i}_bn"; } var bn = LayerUtils.NormLayer(norm_layer, norm_kwargs); @out = bn.Call(@out); } tmp_outputs.Add(@out); } if (use_p6) { outputs = tmp_outputs.Take(tmp_outputs.Count - 1).ToList(); outputs.Add(y_p6); } else { outputs = tmp_outputs.Take(tmp_outputs.Count - 1).ToList(); } base.Construct(outputs, inputs, @params); }
public void switchChar(Collider2D collin) { switch (collin.name) { case "CenterDiamond": //if (!CD.GetComponent<Collider2D>().isTrigger) //{ // CD.GetComponent<Collider2D>().isTrigger = true; //} makeAllDissapear(); Leslie.SetActive(true); TextObject.GetComponentInChildren <Text>().text = "Leslie"; curChar = SelectableCharacters.Leslie; break; case "NorthDiamond": makeAllDissapear(); Jona.SetActive(true); TextObject.GetComponentInChildren <Text>().text = "Jona"; curChar = SelectableCharacters.Jona; break; case "NorthEastDiamond": makeAllDissapear(); Ashita.SetActive(true); TextObject.GetComponentInChildren <Text>().text = "Ashita"; curChar = SelectableCharacters.Ashita; break; case "EastDiamond": makeAllDissapear(); Catarine.SetActive(true); TextObject.GetComponentInChildren <Text>().text = "Catarine"; curChar = SelectableCharacters.Catarine; break; case "SouthEastDiamond": makeAllDissapear(); Ramsey.SetActive(true); TextObject.GetComponentInChildren <Text>().text = "Ramsey"; curChar = SelectableCharacters.Ramsey; break; case "SouthDiamond": makeAllDissapear(); Drogas.SetActive(true); TextObject.GetComponentInChildren <Text>().text = "Drogas"; curChar = SelectableCharacters.Drogas; break; case "SouthWestDiamond": makeAllDissapear(); Sylvia.SetActive(true); TextObject.GetComponentInChildren <Text>().text = "Sylvia"; curChar = SelectableCharacters.Sylvia; break; case "WestDiamond": makeAllDissapear(); Bjin.SetActive(true); TextObject.GetComponentInChildren <Text>().text = "Bjin"; curChar = SelectableCharacters.Bjin; break; case "NorthWestDiamond": makeAllDissapear(); Xavier.SetActive(true); TextObject.GetComponentInChildren <Text>().text = "Xavier"; curChar = SelectableCharacters.Xavier; break; default: break; } }
public void selectChar() { switch (curChar) { case SelectableCharacters.Leslie: TextObject.GetComponentInChildren <Text>().text = "Leslie Selected"; Leslie.GetComponent <Image>().sprite = SelectedImages[0]; CD.GetComponent <Collider2D>().isTrigger = false; break; case SelectableCharacters.Jona: TextObject.GetComponentInChildren <Text>().text = "Jona Selected"; Jona.GetComponent <Image>().sprite = SelectedImages[1]; ND.GetComponent <Collider2D>().isTrigger = false; break; case SelectableCharacters.Ashita: TextObject.GetComponentInChildren <Text>().text = "Ashita Selected"; Ashita.GetComponent <Image>().sprite = SelectedImages[2]; NED.GetComponent <Collider2D>().isTrigger = false; break; case SelectableCharacters.Catarine: TextObject.GetComponentInChildren <Text>().text = "Catarine Selected"; Catarine.GetComponent <Image>().sprite = SelectedImages[3]; ED.GetComponent <Collider2D>().isTrigger = false; break; case SelectableCharacters.Ramsey: TextObject.GetComponentInChildren <Text>().text = "Ramsey Selected"; Ramsey.GetComponent <Image>().sprite = SelectedImages[4]; SED.GetComponent <Collider2D>().isTrigger = false; break; case SelectableCharacters.Drogas: TextObject.GetComponentInChildren <Text>().text = "Drogas Selected"; Drogas.GetComponent <Image>().sprite = SelectedImages[5]; SD.GetComponent <Collider2D>().isTrigger = false; break; case SelectableCharacters.Sylvia: TextObject.GetComponentInChildren <Text>().text = "Sylvia Selected"; Sylvia.GetComponent <Image>().sprite = SelectedImages[6]; SWD.GetComponent <Collider2D>().isTrigger = false; break; case SelectableCharacters.Bjin: TextObject.GetComponentInChildren <Text>().text = "Bjin Selected"; Bjin.GetComponent <Image>().sprite = SelectedImages[7]; WD.GetComponent <Collider2D>().isTrigger = false; break; case SelectableCharacters.Xavier: TextObject.GetComponentInChildren <Text>().text = "Xavier Selected"; Xavier.GetComponent <Image>().sprite = SelectedImages[8]; NWD.GetComponent <Collider2D>().isTrigger = false; break; default: break; } characterChosen = true; weaponMenu(); }