use of edu.stanford.nlp.scenegraph.image.SceneGraphImage in project CoreNLP by stanfordnlp.
the class SceneGraphSentenceMatcher method main.
public static void main(String[] args) throws IOException {
String filename = args[0];
BufferedReader reader = IOUtils.readerFromString(filename);
List<SceneGraphImage> images = Generics.newLinkedList();
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
SceneGraphImage img = SceneGraphImage.readFromJSON(line);
if (img == null) {
continue;
}
images.add(img);
}
}
use of edu.stanford.nlp.scenegraph.image.SceneGraphImage in project CoreNLP by stanfordnlp.
the class SceneGraphImageFilter method main.
public static void main(String[] args) throws IOException {
String filename = args[0];
int threshold = Integer.parseInt(args[1]);
BufferedReader reader = IOUtils.readerFromString(filename);
List<SceneGraphImage> images = Generics.newLinkedList();
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
SceneGraphImage img = SceneGraphImage.readFromJSON(line);
if (img == null) {
continue;
}
images.add(img);
}
countAll(images);
filterRegions(images, threshold);
for (SceneGraphImage img : images) {
if (!img.regions.isEmpty()) {
System.out.println(img.toJSON());
}
}
}
use of edu.stanford.nlp.scenegraph.image.SceneGraphImage in project CoreNLP by stanfordnlp.
the class SceneGraphImageFilter method filterRegions.
private static void filterRegions(List<SceneGraphImage> images, int threshold) {
int regionCount = 0;
int filterCount = 0;
int imgCount = 0;
int removedEntireImgCount = 0;
int removedPartialImgCount = 0;
for (SceneGraphImage img : images) {
imgCount++;
List<SceneGraphImageRegion> toDelete = Generics.newLinkedList();
for (SceneGraphImageRegion region : img.regions) {
regionCount++;
boolean delete = false;
for (SceneGraphImageAttribute attr : region.attributes) {
if (attributeCounter.getCount(attr.attributeLemmaGloss()) < threshold || entityCounter.getCount(attr.subjectLemmaGloss()) < threshold) {
delete = true;
break;
}
}
if (delete) {
toDelete.add(region);
continue;
}
for (SceneGraphImageRelationship reln : region.relationships) {
if (entityCounter.getCount(reln.objectLemmaGloss()) < threshold || entityCounter.getCount(reln.subjectLemmaGloss()) < threshold || relationCounter.getCount(reln.predicateLemmaGloss()) < threshold) {
delete = true;
break;
}
}
if (delete) {
toDelete.add(region);
continue;
}
}
for (SceneGraphImageRegion region : toDelete) {
img.removeRegion(region);
filterCount++;
}
if (!toDelete.isEmpty()) {
removedPartialImgCount++;
}
if (img.regions.isEmpty()) {
removedEntireImgCount++;
}
}
System.err.printf("%d\t%f\t%f\t%f %n", filterCount, filterCount * 100.0 / regionCount, removedPartialImgCount * 100.0 / imgCount, removedEntireImgCount * 100.0 / imgCount);
}
use of edu.stanford.nlp.scenegraph.image.SceneGraphImage in project CoreNLP by stanfordnlp.
the class BoWSceneGraphParser method loadImages.
/**
* Loads scene graphs from JSON file.
*
* @param filename Path to JSON file.
* @return List with images parsed to SceneGraphImage.
* @throws IOException
*/
public static List<SceneGraphImage> loadImages(String filename) throws IOException {
List<SceneGraphImage> images = Generics.newLinkedList();
BufferedReader reader = IOUtils.readerFromString(filename);
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
SceneGraphImage img = SceneGraphImage.readFromJSON(line);
if (img == null) {
continue;
}
images.add(img);
}
return images;
}
use of edu.stanford.nlp.scenegraph.image.SceneGraphImage in project CoreNLP by stanfordnlp.
the class ObjectSceneGraphParser method main.
public static void main(String[] args) throws IOException {
ObjectSceneGraphParser parser = new ObjectSceneGraphParser(args[1]);
BufferedReader reader = IOUtils.readerFromString(args[0]);
SceneGraphEvaluation eval = new SceneGraphEvaluation();
String evalFilePrefix = args[2];
String embeddingsPath = args[3];
parser.embeddings = new Embedding(embeddingsPath);
PrintWriter predWriter = null;
PrintWriter goldWriter = null;
if (evalFilePrefix != null) {
String predEvalFilePath = evalFilePrefix + ".smatch";
String goldEvalFilePath = evalFilePrefix + "_gold.smatch";
predWriter = IOUtils.getPrintWriter(predEvalFilePath);
goldWriter = IOUtils.getPrintWriter(goldEvalFilePath);
}
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
SceneGraphImage img = SceneGraphImage.readFromJSON(line);
if (img == null) {
continue;
}
for (SceneGraphImageRegion region : img.regions) {
SemanticGraph sg = region.getEnhancedSemanticGraph();
SceneGraph scene = parser.parse(sg);
System.out.println(scene.toJSON(img.id, img.url, region.phrase));
if (evalFilePrefix != null) {
eval.toSmatchString(scene, region, predWriter, goldWriter);
}
}
}
}
Aggregations