Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test the pre-trained model on new image? #9

Closed
nitish11 opened this issue May 25, 2020 · 2 comments
Closed

How to test the pre-trained model on new image? #9

nitish11 opened this issue May 25, 2020 · 2 comments

Comments

@nitish11
Copy link

Given, I have downloaded the pre-trained model and weights from the given link below :
https://github.com/czq142857/IM-NET#datasets-and-pre-trained-weights

If I want to run the test on a new image for generating mesh model, will the code work just by changing the below block with my own input_image_path and reading the image?
https://github.com/czq142857/IM-NET/blob/master/IMSVR/model.py#L489-L491

Do I need to do some more processing for the new input image?

@czq142857
Copy link
Owner

Yes. You can simply change the "image loader" block to read your images and run the network.

There is one thing to notice.
The network is trained only on synthetic images, which means, all the training images have certain properties that may not be generalizable, for example:

  1. all images have clear white backgrounds and are gray-scale.
  2. all images are squares and are 128x128.
  3. The objects in the images are centered and have similar sizes (because the synthetic images are rendered on normalized shapes).

You can visualize some training/testing images to get a feel of what kinds of inputs are acceptable.
There is still a long way to go before the method can be used on arbitrary input images.

@nitish11
Copy link
Author

nitish11 commented Jun 12, 2020

Thanks @czq142857 for the suggestion.
I have added a test code to generate 3D models from test_images, you need to put the images in input_test_images folder, add this function in the code and it will generate 3D mesh models (in .ply format) in output_3D_model folder.

def test_image(self, config):
	self.saver = tf.train.Saver()
	could_load, checkpoint_counter = self.load(self.checkpoint_dir)
	if could_load:
		print(" [*] Load SUCCESS")
	else:
		print(" [!] Load failed...")
		return
	
	add_out = "./output_3D_model/"
	add_image = "./input_test_images/"

	offset_x = int(self.crop_edge/2)
	offset_y = int(self.crop_edge/2)
	
	self.sampling_threshold = 0.5
	print("-- self.sampling_threshold :", self.sampling_threshold)

	for t,img_path in enumerate(os.listdir(add_image)):
		print('-'*30)
		img_add = add_image+img_path

		print(img_add)
		print(np.shape(cv2.imread(img_add)))
		
		imgo_ = cv2.imread(img_add, cv2.IMREAD_GRAYSCALE)
		img = cv2.resize(imgo_, (self.view_size,self.view_size))
		
		batch_view = np.reshape(img,(1,self.view_size,self.view_size,1))
		batch_view = batch_view[:, offset_y:offset_y+self.crop_size, offset_x:offset_x+self.crop_size, :]
		batch_view = batch_view/255.0		
		print('-- batch_view :', np.shape(batch_view))

		model_z = self.sess.run(self.sE,
			feed_dict={
				self.view_test: batch_view,
			})
		
		print('-- model_z :', np.shape(model_z))
		model_float = self.z2voxel(model_z)
		print('-- model_float :', np.shape(model_float))
		
		vertices, triangles = mcubes.marching_cubes(model_float, self.sampling_threshold)
		vertices = (vertices-0.5)/self.real_size-0.5
		#vertices = self.optimize_mesh(vertices,model_z)
		print('-- vertices :', np.shape(vertices))
		print('-- triangles :', np.shape(triangles))

		write_ply(add_out+os.path.basename(img_path)[:-4]+".ply", vertices, triangles)
		print("[sample]")

The code works for the pre-trained models to generate 3D mesh models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants