본문 바로가기
728x90

딥러닝6

Tensorflow vs Pytorch 명령어 비교 -(6) tf.zeros(shape, dtype=tf.dtypes.float32, name=None) with tf.Session() as sess: print(sess.run(tf.zeros([3, 4], tf.int32))) print(sess.run(tf.zeros([3, 4], tf.float32))) [[0 0 0 0] [0 0 0 0] [0 0 0 0]] [[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]] torch.zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor torch.zeros([3, 4], dtype=torch.int32) torch.. 2021. 6. 3.
Tensorflow vs Pytorch 명령어 비교 -(5) tf.gather(params, indices, validate_indices=None, name=None, axis=None, batch_dims=0) v1 = tf.constant([1, 3, 5, 7, 9, 0, 2, 4, 6, 8]) v2 = tf.constant([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]) with tf.Session() as sess: print(sess.run(tf.gather(v1, [2, 5, 2, 5], axis=0))) print(sess.run(tf.gather(v2, [0, 1], axis=0))) print(sess.run(tf.gather(v2, [0, 1], axis=1))) [5 0 5 0] [[ 1 2 3 4 5 6] [.. 2021. 6. 2.
Tensorflow vs Pytorch -(4) tf.transpose(a) x = tf.constant([[1, 2, 3], [4, 5, 6]]) x2 = tf.transpose(x) with tf.Session() as sess: print(sess.run(x)) print(sess.run(x2)) [[1, 2, 3], [4, 5, 6]] [[1 4] [2 5] [3 6]] torch.transpose(input, dim0, dim1) x = torch.tensor([[1, 2, 3], [4, 5, 6]]) torch.transpose(x, 0, 1) tensor([[1, 2, 3], [4, 5, 6]]) tensor([[1, 4], [2, 5], [3, 6]]) dim0과 dim1을 swap한다. Loss function # mean square.. 2021. 5. 19.
Tensorflow vs Pytorch 명령어 비교 - (2) tf.boolean_mask(tensor, mask, name='boolean_mask', axis=No) tensor = [0, 1, 2, 3] mask = np.array([True, False, True, False]) tensor2 = [[1, 2], [3, 4], [5, 6]] mask2 = np.array([True, False, True]) with tf.Session() as sess: print(sess.run(tf.boolean_mask(tensor, mask))) print(sess.run(tf.boolean_mask(tensor2, mask2))) [0 2] [[1 2] [5 6]] torch.masked_select(input, mask, *, out=None) tensor = t.. 2021. 5. 15.
Tensorflow vs Pytorch 명령어 비교 tf.argsort(values, axis=-1, direction='ASCENDING') arr = [1, 2, 3, 10, 5, 6] arr_ascending = tf.argsort(arr, axis=-1, direction='ASCENDING') arr_descending = tf.argsort(arr, axis=-1, direction='DESCENDING') with tf.Session() as sess: print(sess.run(arr_ascending)) print(sess.run(arr_descending)) # ----------------------------------- arr2 = [[1, 2], [4, 8], [5, 3], [2, 7]] print(np.array(arr2).sh.. 2021. 5. 14.
Tensorflow data pipeline 구축 Tensorflow에서 feed_dict로 데이터를 계속해서 공급하는 코드를 많이 보셨을것입니다. 그러나, 논문을 리뷰하면서 github 참조를 많이 하셨던 분들은 아시겠지만 feed_dict로 데이터를 공급하는 코드는 거의 없던것 같습니다. 또한 데이터를 로드하는 bottleneck 시간이 줄어들어서 학습시간이 줄어드는 효과가 있습니다. 이에 본 블로그에서는 data를 gpu에 계속해서 공급하는 tensorflow기반 dataset api를 참고해서 설명을 드리고자합니다. 1. Tensorflow dataset 불러오기 numpy를 이용해서 데이터 만들기 features, labels = (np.random.sample((100,2)), np.random.sample((100,1))) dataset =.. 2021. 5. 13.
728x90