zlzeng / DeepFloorplan

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How I solve the problem about r2v dataset and roomtype error

krus1995 opened this issue · comments

commented

First of all, thanks to @zlzeng sent me txt of origin name by correct order, which give me feasibility to modify these files into correct correspondence. If you need the raw txt, check the file below.
test.txt
train.txt
val.txt

If you don't want to know what happens, just find the summary in the end.

To train model with r2v dataset, we need to correct the correspondence in txt file and change a little bit code. Let's see how to get through this. You can download r2v origin data from here.

Modify txt file
First I merged zlzeng's txt and project's txt, the result looks like:

../dataset/floorplan_image/04/94/1b4b5b3a8dcbe2135310d067eb6e/0001.jpg ../dataset/jp/test/1_wall.png ../dataset/jp/test/1_close.png ../dataset/jp/test/1_rooms.png ../dataset/jp/test/1_close_wall.png
../dataset/floorplan_image/08/fe/cb1ded96be76713683c50e731f3f/0001.jpg ../dataset/jp/test/2_wall.png ../dataset/jp/test/2_close.png ../dataset/jp/test/2_rooms.png ../dataset/jp/test/2_close_wall.png
../dataset/floorplan_image/04/8c/723a3389ae4aaaa11d3d97123e2d/0001.jpg ../dataset/jp/test/3_wall.png ../dataset/jp/test/3_close.png ../dataset/jp/test/3_rooms.png ../dataset/jp/test/3_close_wall.png
../dataset/floorplan_image/03/c0/fd5d2bb20c86db0c8f24a83b8a3c/0003.jpg ../dataset/jp/test/4_wall.png ../dataset/jp/test/4_close.png ../dataset/jp/test/4_rooms.png ../dataset/jp/test/4_close_wall.png
../dataset/floorplan_image/00/23/500a167ab926df601817631d6733/0002.jpg ../dataset/jp/test/5_wall.png ../dataset/jp/test/5_close.png ../dataset/jp/test/5_rooms.png ../dataset/jp/test/5_close_wall.png
../dataset/floorplan_image/01/e5/df6969c71c4cb3b786cde09b4efc/0002.jpg ../dataset/jp/test/6_wall.png ../dataset/jp/test/6_close.png ../dataset/jp/test/6_rooms.png ../dataset/jp/test/6_close_wall.png
../dataset/floorplan_image/08/3c/4144463ce4d677723e9032358408/0002.jpg ../dataset/jp/test/7_wall.png ../dataset/jp/test/7_close.png ../dataset/jp/test/7_rooms.png ../dataset/jp/test/7_close_wall.png
../dataset/floorplan_image/09/22/b9bd969fff7820dbdbc660b6df26/0001.jpg ../dataset/jp/test/8_wall.png ../dataset/jp/test/8_close.png ../dataset/jp/test/8_rooms.png ../dataset/jp/test/8_close_wall.png
../dataset/floorplan_image/02/d4/6ab7b8396d8f24c31ea2e8a0e2f2/0003.jpg ../dataset/jp/test/9_wall.png ../dataset/jp/test/9_close.png ../dataset/jp/test/9_rooms.png ../dataset/jp/test/9_close_wall.png
../dataset/floorplan_image/00/99/28fbde7b272adad6da35f0bc16c3/0001.jpg ../dataset/jp/test/10_wall.png ../dataset/jp/test/10_close.png ../dataset/jp/test/10_rooms.png ../dataset/jp/test/10_close_wall.png

Then I try to run main.py --phase test, it works well but when I check ./out directory, I found that results were overwritten by itself because of the name of origin file is almost the same like 0001.jpg. So we have to change name of images and path in txt.
I write a simple script to do this task:

Before running the script below, you should download those files and put it into ./dataset
r2v_train.txt
r2v_test.txt

# DeepFloorplan/utils/txt_modify.py
import os


TRAIN_TXT = "r2v_train.txt"
TEST_TXT = "r2v_test.txt"


if __name__ == "__main__":
    for txt_name in [TRAIN_TXT, TEST_TXT]:
        root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../dataset"))
        print(root_path)
        txt_path = os.path.join(root_path, txt_name)
        print(txt_path)

        with open(txt_path) as file:
            lines = file.read().splitlines()

        path = [[line.split("\t")[0], line.split("\t")[1]] for line in lines]
        
        target_path = []
        for origin, target in path:
            root, origin_name = os.path.split(origin)
            target_name = os.path.basename(target).split("_")[0] + ".jpg"
            
            try:
                os.rename(origin, os.path.join(root, target_name))
            except OSError:
                print("No such file or directory {}".format(origin))
            
            target_path.append(os.path.join(root, target_name))
        
        path = [line.split("\t") for line in lines]
        for line, target_path in zip(path, target_path):
            line[0] = target_path
            
        with open(txt_name, "w+") as file:
            for line in path:
                file.write("\t".join(line))
                file.write("\r\n")

When I run this script I got an IO Error so I add try block to figure out what happened:

No such file or directory ../dataset/floorplan_image/04/94/1b4b5b3a8dcbe2135310d067eb6e/1.jpg
No such file or directory ../dataset/floorplan_image/08/fe/cb1ded96be76713683c50e731f3f/2.jpg
No such file or directory ../dataset/floorplan_image/04/8c/723a3389ae4aaaa11d3d97123e2d/3.jpg
No such file or directory ../dataset/floorplan_image/03/c0/fd5d2bb20c86db0c8f24a83b8a3c/4.jpg
No such file or directory ../dataset/floorplan_image/00/23/500a167ab926df601817631d6733/5.jpg
No such file or directory ../dataset/floorplan_image/01/e5/df6969c71c4cb3b786cde09b4efc/6.jpg
No such file or directory ../dataset/floorplan_image/08/3c/4144463ce4d677723e9032358408/7.jpg
No such file or directory ../dataset/floorplan_image/09/22/b9bd969fff7820dbdbc660b6df26/8.jpg
No such file or directory ../dataset/floorplan_image/02/d4/6ab7b8396d8f24c31ea2e8a0e2f2/9.jpg
No such file or directory ../dataset/floorplan_image/00/99/28fbde7b272adad6da35f0bc16c3/10.jpg

Seem like we loss 10 images. I checked directory and find out that there are ten duplication usages in txt file. These ten images are used in both training and test task.

To solve this problem, we have three choices (I choose solution 2)

  1. Training a model use first merged txt file (without change filename)
  2. copy these images and rename it by yourself
  3. find all code of read image and use try block to catch the error

Finally, we have correct txt file and ready for training. Before training in large dataset, you should check the output of model whether room type can be predicted.

Modify code
If the room type can't be predicted, replaceself.loss_type = 'balanced' in main.py with self.loss_type = ''. More information please check this issue.

Simple version
To summarize, you should

  1. download r2v origin data from here
  2. download the txt file and put it into ./dataset
    r2v_train.txt
    r2v_test.txt
  3. run the script and solve the duplication problem
  4. follow "the steps of training and validation in this project"

Those are the steps of training and validation in this project

  1. prepare data and txt
  2. run ./utils/create_tfrecord.py to create tfrecord of data (r2v or r3d)
  3. run ./main.py --phase train (sr2v or r3d)
  4. run ./main.py --phase test (r2v or r3d)
  5. check result from ./out
  6. run ./scores.py for calculate ACC and IoU

Hope helpful.
Please reply if there are any mistake or suggestion.

hi, I can not find any train-input-img in r2v
image

commented

hi, I can not find any train-input-img in r2v image

I remember the "train input image" is these "_multi" images.