Fix bug that make img be None in the first sample.