|
- #!/usr/bin/env python
- # coding: utf-8
- """
- @Author: Dinghao Yang
- @Contact: dinghaoyang@gmail,cin
- @Time: 2020/9/28 7:29 PM
-
- """
-
-
- import os
- import glob
- import h5py
- import numpy as np
- from sklearn import manifold
-
- # In[3]:
-
- def load_data(partition):
- DATA_DIR = './data'
- all_data = []
- all_label = []
- for h5_name in glob.glob(os.path.join(DATA_DIR, 'modelnet40*hdf5_2048', '*%s*.h5'%partition)):
- f = h5py.File(h5_name, 'r+')
- data = f['data'][:].astype('float32')
- label = f['label'][:].astype('int64')
- f.close()
- all_data.append(data)
- all_label.append(label)
- all_data = np.concatenate(all_data, axis=0)
- all_label = np.concatenate(all_label, axis=0)
- return all_data, all_label
-
-
- # In[4]:
-
-
- train_data, train_label = load_data('train')
-
-
-
- train_data_lle = []
- for i,x in enumerate(train_data):
- print('Processing sample%d'%i)
- x_lle, err = manifold.locally_linear_embedding(x, n_neighbors=12,
- n_components=2)
- x_new = np.concatenate((x, x_lle),axis=1)
- train_data_lle.append(x_new)
- print('Finish LLE!')
-
- train_data_lle = np.array(train_data_lle)
-
- f = h5py.File('./data/modelnet40_train_add_lle.h5','w')
- f['data'] = train_data_lle
- f['label'] = train_label
- f.close()
-
-
-
- # Test data
- test_data, test_label = load_data('test')
-
- # In[52]:
-
-
- test_data_lle = []
- for i,x in enumerate(test_data):
- print('Processing sample%d'%i)
- x_lle, err = manifold.locally_linear_embedding(x, n_neighbors=12,
- n_components=2)
- x_new = np.concatenate((x, x_lle),axis=1)
- test_data_lle.append(x_new)
- print('Finish LLE!')
-
-
- # In[53]:
-
-
- test_data_lle = np.array(test_data_lle)
-
-
-
- f = h5py.File('./data/modelnet40_test_add_lle.h5','w')
- f['data'] = test_data_lle
- f['label'] = test_label
- f.close()
-
|