Giter Site home page Giter Site logo

Inferene on my own dataset about dmh-net HOT 2 CLOSED

starrah avatar starrah commented on August 22, 2024
Inferene on my own dataset

from dmh-net.

Comments (2)

Starrah avatar Starrah commented on August 22, 2024

Hello!
The .txt files contain information about the ground truth corners. In evaluation mode, we need the .txt files to calculate metrics like 3DIoU.
Of course, you may not need the files if you just want to inference on your images, without calculating metrics.
In such situation, you have two methods:

First, you may modify the code.
Remove the lines that read .txt files, so that self.cors keeps equals to []

for filename in self.img_fnames:
with open(os.path.join(self.cor_dir, filename[:-4] + ".txt")) as f:
cor = np.array([line.strip().split() for line in f if line.strip()], np.float32)
self.cors.append(cor)

Change the line to return self.getItem(self.img_fnames[idx], None)
return self.getItem(self.img_fnames[idx], self.cors[idx])

And the most important, modify the getItem function,
def getItem(self, filename, cor=None):

remove all code lines that requires the cor variable to calculate. Those may include:
if self.cfg.MODEL.HOUGH.CLINE_TYPE == "NEW":
liness.append(np.array(d["lines"]))
try:
peaks = self.linesToPeaksNew(d["lines"], self.view_size)
except:
assert False, AUG_RECORD
peakss.append(peaks)
peaks_for_label = peaks
label_hw = self.view_size
xPeaks, yPeaks, cUpPeaks, cDownPeaks = peaks_for_label
xLabels.append(
self.generate_gradual_hough_label(xPeaks, label_hw[1], type=self.hough_label_gradual_type,
base=self.cfg.MODEL.HOUGH.GRADUAL_LABEL.XY))
yLabels.append(
self.generate_gradual_hough_label(yPeaks, label_hw[0], type=self.hough_label_gradual_type,
base=self.cfg.MODEL.HOUGH.GRADUAL_LABEL.XY))
cline_angle_num = label_hw[1] + label_hw[0] // 2 * 2 - 2
cUpLabels.append(
self.generate_gradual_hough_label(cUpPeaks, cline_angle_num, type=self.hough_label_gradual_type,
base=self.cfg.MODEL.HOUGH.GRADUAL_LABEL.CUPDOWN))
cDownLabels.append(
self.generate_gradual_hough_label(cDownPeaks, cline_angle_num, type=self.hough_label_gradual_type,
base=self.cfg.MODEL.HOUGH.GRADUAL_LABEL.CUPDOWN))
else:
raise NotImplementedError()
n_cor = len(cor)
gt_floor_coor = cor[1::2]
gt_ceil_coor = cor[0::2]
gt_floor_xyz = np.hstack([
post_proc.np_coor2xy(gt_floor_coor, self.ch, self.W, self.H, floorW=1, floorH=1),
np.zeros((n_cor // 2, 1)) + self.ch,
])
gt_c = np.sqrt((gt_floor_xyz[:, :2] ** 2).sum(1))
gt_v2 = post_proc.np_coory2v(gt_ceil_coor[:, 1], self.H)
gt_ceil_z = gt_c * np.tan(gt_v2)
height = np.array([gt_ceil_z.mean() - self.ch], dtype=np.float32)
# Convert all data to tensor
e_img = torch.FloatTensor(e_img.transpose([2, 0, 1]))
# angle = torch.FloatTensor(angle)
# up_bin256 = torch.FloatTensor(up_bin256.copy())
# down_bin256 = torch.FloatTensor(down_bin256.copy())
height = torch.FloatTensor(height)

and delete the affected keys from the returned dict, which may include cor, height, *Labels, lines, peaks
out_dict = {
"filename": filename,
"e_img": e_img,
"cor": cor,
"height": height,
"p_imgs": torch.stack(p_imgs, 0),
"xLabels": np.array(xLabels).astype(np.float32),
"yLabels": np.array(yLabels).astype(np.float32),
"cUpLabels": np.array(cUpLabels).astype(np.float32),
"cDownLabels": np.array(cDownLabels).astype(np.float32),
"peaks": peakss,
"lines": liness
}
return out_dict

And, change this line to r = {}
r = generateOnePerspectiveLabel(e_img, cor, *view, VIEW_SIZE)

I think those may enough, but I cannot guarantee it. The principal is to remove all place that use the cor variable, so if you meets with any error about not finding the cor, just feel free to remove it.

Or, you may have another option to make pesudo .txt files. The example is:

85 175
85 349
376 142
376 383
710 186
710 336
878 196
878 325

In which each lines represents the coordinate of a corner point in the image. Note that if you make pesudo .txt files, the metrics output of our code is totally meaningless.

from dmh-net.

ghvision avatar ghvision commented on August 22, 2024

Thank you for your kind reply.

I modified the code and it works fine!

from dmh-net.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.