Imported from https://github.com/Bihaqo/TensorNet