public List <TextCaption> GetTextCaptionFromDencap(List <DenseCap> denseCap) { int take = 10; if (denseCap == null || denseCap.Count <= 0) { return(null); } List <TextCaption> textCaptions = new List <TextCaption>(); //4593 file foreach (DenseCap itemDenseCap in denseCap) { String inputDir = itemDenseCap.opt.input_dir; for (int i = 0; i < itemDenseCap.results.Count; i++) { TextCaption textCaption = new TextCaption(); textCaption.FrameName = Path.Combine(inputDir, itemDenseCap.results[i].img_name); StringBuilder builder = new StringBuilder(); int takeCaption = Math.Min(take, itemDenseCap.results[i].captions.Count); for (int j = 0; j < takeCaption; j++) { builder.Append(itemDenseCap.results[i].captions[j] + ","); } textCaption.Caption = builder.ToString(); textCaptions.Add(textCaption); } } return(textCaptions); }
/// <summary> /// Add Document TextCaption to IndexStorage /// </summary> /// <param name="indexStorage">Index Storage</param> /// <param name="textCaption">TextCaption data</param> public static void AddDocumentToIndexStorage(IndexStorage indexStorage, TextCaption textCaption) { Document doc = new Document(); doc.Add(new Field(FRAME_NAME, textCaption.FrameName, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(TEXT_CAPTION, textCaption.Caption, Field.Store.YES, Field.Index.ANALYZED)); indexStorage.GetIndexWriter().AddDocument(doc); }
public void DecodeTextCaptionFromDencap(String jsonCaptionPath, String ouputFile) { int take = 10; if (!Directory.Exists(jsonCaptionPath)) { return; } String[] files = Directory.GetFiles(jsonCaptionPath); List <TextCaption> textCaptions = new List <TextCaption>(); for (int index = 0; index < files.Length; index++) { DenseCap itemDenseCap = DecodeDenseCap(files[index]); String inputDir = itemDenseCap.opt.input_dir; for (int i = 0; i < itemDenseCap.results.Count; i++) { TextCaption textCaption = new TextCaption(); textCaption.FrameName = Path.Combine(inputDir, itemDenseCap.results[i].img_name); StringBuilder builder = new StringBuilder(); int takeCaption = Math.Min(take, itemDenseCap.results[i].captions.Count); for (int j = 0; j < takeCaption; j++) { builder.Append(itemDenseCap.results[i].captions[j] + ","); } textCaption.Caption = builder.ToString(); builder = null; textCaptions.Add(textCaption); } if ((index != 0 && (index % 500 == 0)) || index == (files.Length - 1)) { Console.WriteLine("WriteJson"); String str = JsonConvert.SerializeObject(textCaptions); WriteFile(str, "densecap_json_" + index.ToString() + ".json"); textCaptions.Clear(); } itemDenseCap = null; } textCaptions = null; }